aspose file tools
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
Register / Login
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Reply 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://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: How to avoid persisting a child object, which is already there in database?
 
Similar Threads
one to one unidirectional mapping in jpa
Persist Object in Data Base
Color in JTable
Problem with persisting entities because they become detached
Created blob cloumn for @OneToOne relation on gettermethod