I'll have to check when I get home the exact way, but you definetly don't
need a primary key, just the composite key of person_id and request_id.
Not 100% sure, but I think when you build the appfuse project then the one
to many and many to one annotations will do the id's for you.
So all you need in the PersonRequest model is the getters and setters.

Cheers
Aled

-----Original Message-----
From: syg6 [mailto:[EMAIL PROTECTED] 
Sent: 09 July 2007 15:21
To: [email protected]
Subject: [appfuse-user] RE: RE: many-to-many with attribute ... again


I figured it out. My fault. Forgot to put @Entity in the Person class!

One last question - I think PersonRequest should have a combination of
'person_id' and 'request_id' as its primary key, how can I do that?
Currently it has its own auto-numeric key but I think it's more correct to
use a composite key ...

Thanks again,
Bob


syg6 wrote:
> 
> Yup. I have all 3 classes in my hibernate.cfg.xml:
> 
> <mapping class="com.mycompany.app.model.Person"/>
> <mapping class="com.mycompany.app.model.Request"/>
> <mapping class="com.mycompany.app.model.PersonRequest"/>
> 
> I also tried deleting PersonRequest from the hibernate.cfg.xml because I
> wasn't sure if it needed to be defined or not. But I got a different error
> so, I guess it does.
> 
> I'll keep trying ...
> 
> Thanks!
> Bob
> 
> 
> 
> Aled Rhys Jones wrote:
>> 
>> Yeah, you have to have a model for PersonRequest since you need to know
>> the
>> date object it holds.  Any other method and it's not many to many.
>> 
>> Regarding the error, have you defined all the models in the hibernate
>> configuration file (hibernate.cfg.xml)?
>> 
>> 
>> -----Original Message-----
>> From: syg6 [mailto:[EMAIL PROTECTED] 
>> Sent: 09 July 2007 14:08
>> To: [email protected]
>> Subject: [appfuse-user] RE: many-to-many with attribute ... again
>> 
>> 
>> 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.h
>> tml#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]
>> 
>> 
>> 
>> ---------------------------------------------------------------------
>> 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.h
tml#a11502757
Sent from the AppFuse - User mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to