-->
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.  [ 5 posts ] 
Author Message
 Post subject: Annotation + CascadeType.All & CascadeType.DELETE_ORPHAN
PostPosted: Fri Aug 05, 2005 5:24 am 
Newbie

Joined: Tue Aug 02, 2005 2:42 pm
Posts: 7
Hey, those that know - I need the all-delete-orphan cascade type for a set ( bidirectional one-to-many ), and when I use this <see below>. It appears to be there, but I'm just not using it rigth. Any ideas? ( thanks in advance )

@OneToMany( cascade = { CascadeType.ALL, org.hibernate.annotations.CascadeType.DELETE_ORPHAN )

I get these two error's:

Type missmatch: cannot convert CascadeType to CascadeType

and

[javac] /home/mike1/Desktop/MyBusinessStuff/STB Technologies LTD/code/Java/Working/HBM/HBM Web UnsafeObjects/WEB-INF/src/com/sas/heartbeatmonitor/businessobjects/Location.java:55: incompatible types
[javac] found : org.hibernate.annotations.CascadeType
[javac] required: javax.persistence.CascadeType
[javac] @OneToMany( cascade = { CascadeType.ALL, org.hibernate.annotations.CascadeType.DELETE_ORPHAN } )
[javac] ^
[javac] 1 error


Operating System:
FreeBSD 5.4

Hibernate version:
3.1alpha1

Name and version of the database you are using:
MySQL 4.1.12

Java Version:
1.5.0-p1


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 05, 2005 10:48 am 
Newbie

Joined: Tue May 31, 2005 8:57 am
Posts: 10
Hi,

You are mixing two enums with similar names:
- javax.persistence.CascadeType
- org.hibernate.annotations.CascadeType

The @OneToMany annotation expects only the first one, so your @OneToMany should read:
Code:
@OneToMany(cascade = CascadeType.ALL)


To also specify DELET_ORPHAN, I do the following but I'm not sure whether its necessary:
Code:
@Cascade({ org.hibernate.annotations.CascadeType.ALL, org.hibernate.annotations.CascadeType.DELETE_ORPHAN })


The @Cascade annotation is from the package org.hibernate.annotations.

Regards,
Ronald Wildenberg


Top
 Profile  
 
 Post subject: We'll that makes sence and compiles, but now
PostPosted: Fri Aug 05, 2005 3:05 pm 
Newbie

Joined: Tue Aug 02, 2005 2:42 pm
Posts: 7
public Set<Contact> getContacts(){
return contacts;
}

only returns a set with one object in it - and when I look at the database - i can see that more contacts are associated than just this one. Is there more info I need to specify in the Client class than just:

@OneToMany(fetch=FetchType.EAGER)
@org.hibernate.annotations.Cascade({org.hibernate.annotations.CascadeType.ALL, org.hibernate.annotations.CascadeType.DELETE_ORPHAN } )
public Set<Contact> getContacts(){
return contacts;
}

------------------
and in the Contact class I have
------------------
@ManyToOne
public Client getClient(){
return client;
}
public void setClient(Client client){
this.client = client;
}


again, this should be a bi-directional association - there is many Contacts for each client - but only one client for each contact.

:-(

mike


Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 08, 2005 3:27 am 
Newbie

Joined: Tue May 31, 2005 8:57 am
Posts: 10
Well, as far as I can tell your code is correct. You could add a mappedBy="client" to your @OneToMany annotation to specify that client is the owning side of the relation, but that is not strictly necessary.


Top
 Profile  
 
 Post subject: Update:
PostPosted: Mon Aug 08, 2005 4:05 pm 
Newbie

Joined: Tue Aug 02, 2005 2:42 pm
Posts: 7
It appears that the problem has nothing to do with the DELETE_ORPHAN.

the problem was in my querries.

crit.setMaxResults(1);

would only return 1 object for each set. So
Client has a set of Locations ( one location returned)
Location has a set of Devices ( one device returned )

So I'd have a "Client" with 1 "Location", with 1 "Device" returned.

:-(

but - remove the setMaxResults() and it starts returning properly.

My bad.

mike


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 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.