Hmm ... well, ideally I was hoping to NOT have to create any extra model
classes. It seems I have to at least create one, right? The PersonRequest
class. Well, at least it seems I don't have to create the PersonRequestPK
class!
Anyway, I tried your example and when I run mvn test-compile
hibernate3:hbm2ddl I get an error:
AnnotationException: @OneToOne or @ManyToOne on
com.mycompany.app.model.PersonRequest.person references an unknown entity:
com.mycompany.app.model.Person
Both Person and Request exist ... Both have the following annotations:
private Long id;
@Id @GeneratedValue(strategy = GenerationType.AUTO)
public Long getId() {
return id;
}
I am not sure what the problem is ... but then I am not an Annotations or
Hibernate expert. I'll keep trying. And further help much appreciated!
Cheers,
Bob
Aled Rhys Jones wrote:
>
> Hi Bob
>
> Ok then, Yes. :-)
>
> http://www.hibernate.org/hib_docs/annotations/reference/en/html_single/
>
> I've got the same scenario in my app.
>
>
>
> Example Request model:
>
> @Entity
>
> public class Request {
>
>
>
> private List<PersonRequest> personRequests;
>
> ......
>
>
>
> @OneToMany(mappedBy="request")
>
> @OrderBy("date")
>
> public List<PersonRequest> getPersonRequests () {
>
> return personRequests;
>
> }
>
> .....
>
> }
>
>
>
> Example Person model:
>
> @Entity
>
> public class Person {
>
> private List<PersonRequest> personRequests;
>
> ......
>
>
>
> @OneToMany(mappedBy="person")
>
> @OrderBy("date")
>
> public List<PersonRequest> getPersonRequests () {
>
> return personRequests;
>
> }
>
> .....
>
> }
>
>
>
> Example PersonRequest model:
>
> @Entity
>
> public class PersonRequest:
>
> private Person person;
>
> private Request request;
>
> .....
>
> @ManyToOne
>
> @JoinColumn(name="person_id")
>
> public Person getPerson(){
>
> return person;
>
> }
>
>
>
> @ManyToOne
>
> @JoinColumn(name="request_id")
>
> public Request getRequest(){
>
> return request;
>
> }
>
> .......
>
> }
>
>
>
> You may want to add details about cascading and the like.
>
> You'll obviously need to put annotations on your getId method's so
> hibernate
> know to use the id fields as primary keys.
>
> Just add in the other fields such as description as normal.
>
> Hope this helps.
>
>
>
> Cheers
>
> Aled
>
>
>
>
>
> -----Original Message-----
> From: syg6 [mailto:[EMAIL PROTECTED]
> Sent: 09 July 2007 12:18
> To: [email protected]
> Subject: [appfuse-user] many-to-many with attribute ... again
>
>
>
>
>
> Hello all.
>
>
>
> I had this problem about a year ago and just couldn't get Hibernate and
>
> XDoclet to play nice. Basically I have this:
>
>
>
> Request
>
> id
>
> description
>
>
>
> Person
>
> id
>
> name
>
>
>
> PersonRequest
>
> idPerson
>
> idRequest
>
> date
>
>
>
> And I would like to know how to do with Annotations. The last time I wound
>
> up hand-hacking the hibernate mapping files and creating two intermediate
>
> 'composite' classes -- let's call them PersonRequest and PersonRequestPK
> --
>
> and having to do all of the DAO by hand.
>
>
>
> Is there any way to do this auto-magically with Annotations?
>
>
>
> Please say yes ...
>
>
>
> Cheers,
>
> Bob
>
> --
>
> View this message in context:
> http://www.nabble.com/many-to-many-with-attribute-...-again-tf4048626s2369.h
> tml#a11499869
>
> Sent from the AppFuse - User mailing list archive at Nabble.com.
>
>
>
> ---------------------------------------------------------------------
>
> To unsubscribe, e-mail: [EMAIL PROTECTED]
>
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>
>
>
>
--
View this message in context:
http://www.nabble.com/many-to-many-with-attribute-...-again-tf4048626s2369.html#a11501267
Sent from the AppFuse - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]