wood burning stoves 2.0*
The moose likes EJB and other Java EE Technologies and the fly likes How to avoid persisting a child object, which is already there in database? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "How to avoid persisting a child object, which is already there in database?" Watch "How to avoid persisting a child object, which is already there in database?" New topic
Author

How to avoid persisting a child object, which is already there in database?

Repala Madhu
Greenhorn

Joined: Jun 12, 2007
Posts: 14
Hello all, i am using EJB 3.0

I have a scenario, where i don't want to persist a child object with @OneToOne annotation.

@Entity(name = "Alarm")
@Table(name = "ALARM")
public class Alarm extends AppMO
{
public Alarm()
{

}
/**
* Constructor - called by the factory.
* @param name Name of this object.
*/
public Alarm(String name, String MOType, String neName)
{
super( name, MOType, neName);
}

@Basic
@OneToOne
private Severity severity = null;

public Severity getSeverity() {
return severity;
}

public void setSeverity(Severity severity) {
this.severity = severity;
}
}


In the above entity, i am setting a Severity object, which is already there in database.
Alarm alarm = new Alarm();
alarm.setSeverity(severity);

Here the alarm is new object. And the alarm object i am sending from my web client.
So, here i don't want to load/find the severity object on to the manager. With out doing this, how can i persist alarm object in database which be having the severity after successful persistent.


Thanks in advance for all the helps....
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to avoid persisting a child object, which is already there in database?
 
Similar Threads
Color in JTable
one to one unidirectional mapping in jpa
Problem with persisting entities because they become detached
Created blob cloumn for @OneToOne relation on gettermethod
Persist Object in Data Base