-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 
Author Message
 Post subject: "all-delete-orphan" with annotations
PostPosted: Mon Jan 24, 2005 3:31 am 
Beginner
Beginner

Joined: Fri Jun 11, 2004 3:42 am
Posts: 22
Hi,

This question has been posted in the forum before and there seem to be no replies for it.

CascadeStrategy with "all-delete-orphan" with annotations does not seem to be implemented with Annotations, possibly because of the limitations of the current EJB 3.0 Spec. But then, there needs to be some solution for itl!! Someone kindly comment or advice and alternative!

Here is a Simple code base that I tried

Code:
@Entity(access = AccessType.FIELD)
public class Customer {

   @Id
   @Column(length=100)
   public String ID;
   public String Name;

   @OneToMany(cascade=CascadeType.ALL, fetch=FetchType.EAGER)
   @JoinColumn(name="CUSTOMER_ID")
   public Set<Ticket> Tickets   = new HashSet();
   
   public Customer() {
   }

   public Customer(String _Name) throws Exception {
      ID = IDGen.generateID();
      Name = _Name;
   }
   
   public Ticket addTicket(String _Number) throws Exception {
      Ticket TicketObj = new Ticket();
      TicketObj.Number = _Number;
      TicketObj.customer = this;
      Tickets.add(TicketObj);
      return TicketObj;
   }
}


Customer <> One-ToMany <> Tickets

Code:
@Entity(access = AccessType.FIELD)
public class Ticket {

   @Id
   @Column(length=100)
   public String ID;
   public String Number;

   @ManyToOne(cascade = CascadeType.ALL)
   @JoinColumn(name="CUSTOMER_ID")
   public Customer customer;
   
   public Ticket() throws Exception {
      ID = IDGen.generateID();
   }
}


Code that uses these relationships

Code:
Customer CustomerObj;
try {
   DatabaseManager.beginTransaction();

   CustomerObj = new Customer("Gyani");
   CustomerObj.addTicket("1");
   CustomerObj.addTicket("2");
   DatabaseManager.getSession(MountPoint).saveOrUpdate(CustomerObj);

   DatabaseManager.commitTransaction();
} catch (Exception ExceptionObj) {
   DatabaseManager.rollbackTransaction();
   throw ExceptionObj;
} finally {
   DatabaseManager.closeSession();
}
//The customer at this point has 2 Tickets

try {
   DatabaseManager.beginTransaction();

   CustomerObj.Tickets = new HashSet();
   CustomerObj.addTicket("3");
   
   DatabaseManager.getSession(MountPoint).saveOrUpdate(CustomerObj);

   DatabaseManager.commitTransaction();
} catch (Exception ExceptionObj) {
   DatabaseManager.rollbackTransaction();
   throw ExceptionObj;
} finally {
   DatabaseManager.closeSession();
}
//The customer at this point has 1 Ticket

try {
   DatabaseManager.beginTransaction();

   CC.Tickets = new HashSet();
   CC.addTicket("3");
   
   DatabaseManager.getSession(MountPoint).saveOrUpdate(CC);

   DatabaseManager.commitTransaction();
} catch (Exception ExceptionObj) {
   DatabaseManager.rollbackTransaction();
   throw ExceptionObj;
} finally {
   DatabaseManager.closeSession();
}
//ERROR Customer should have 1 Tickets, but it reflects that the customer has 3 Tickets, even though the Customer Object has 1 Ticket !!!




Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 24, 2005 4:31 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
We will be introducing an extended annotation set for users who want to take advantage of Hibernate-specific features.

It is also quite likely that the ejb spec will get orphan delete soon.

Cheers, and thanks for the feedback.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 24, 2005 4:49 am 
Beginner
Beginner

Joined: Fri Jun 11, 2004 3:42 am
Posts: 22
Thanks for the reply. Any idea on any tentative dates these extensions will be released, so that we can plan accordingly here.

Thanks!


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 24, 2005 5:31 am 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
The software you are using is alpha, you should not rely on any dates or features at this point in time.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.