-->
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.  [ 3 posts ] 
Author Message
 Post subject: Non-persistable object but needing property persisted
PostPosted: Mon Sep 28, 2009 1:53 pm 
Newbie

Joined: Wed Sep 23, 2009 5:49 pm
Posts: 3
I have a situation that is a little unique to an application that is being developed and curious if Hibernate is able to handle it. So far I have been messing around with it but haven't got it to work. I will be using example classes / data tables but it reflects a similar situation to the application. The mapping is:

Code:
<class name="Person">
    <id name="id">
        <generator class="assigned"/>
    </id>

    <set name="events" table="PERSON_EVENT">
        <key column="PERSON_ID"/>
        <many-to-many column="EVENT_ID" class="Event"/>
    </set>
</class>

<class name="Event" table="EVENTS">
    <id name="id" column="EVENT_ID">
        <generator class="assigned"/>
    </id>
    <property name="date" type="timestamp" column="EVENT_DATE"/>
    <property name="title"/>
</class>


What I am needing is the ability for the Person class objects to not be persisted but when I instantiate a person it will load the corresponding events for that person from the database and populate the set. As well if the events for the person change within the set then an update on the person object would persist those associations but would not try to persist the person itself.

Reasoning behind this is that the person data is being maintained in a separate application so we don't want to duplicate the properties of the person class. Within the other application there is the details about the person (i.e. name, address, etc) and within this application there is just information about the event with the person_event and event tables. I would like to still work with the base classes of Person and Event without having to create some custom PersonEvent object that would need to expose the ability to allow a retrieval of a list of events for a person.

Any way for hibernate to provide this functionality?

Thanks

--
Shawn Clark


Top
 Profile  
 
 Post subject: Re: Non-persistable object but needing property persisted
PostPosted: Mon Sep 28, 2009 2:43 pm 
Senior
Senior

Joined: Mon Jul 07, 2008 4:35 pm
Posts: 141
Location: Berlin
Hi ShawnClark,

how about adding a "fake" foreign key in your Event entity that references the Person's PK? Add a field of the appropriate type to the class and map it like a regular property. The data integrity handling of the FK would of course have to take place in your Event app.

CU
Froestel

_________________
Have you tried turning it off and on again? [Roy]


Top
 Profile  
 
 Post subject: Re: Non-persistable object but needing property persisted
PostPosted: Mon Sep 28, 2009 4:50 pm 
Newbie

Joined: Wed Sep 23, 2009 5:49 pm
Posts: 3
Froestel wrote:
how about adding a "fake" foreign key in your Event entity that references the Person's PK? Add a field of the appropriate type to the class and map it like a regular property. The data integrity handling of the FK would of course have to take place in your Event app.


There isn't a one-to-one relationship between the Event and Person. Which is why there is the PERSON_EVENT table. Even if it is a one-to-one I still want to have a Person class within my application that would only be a skeleton of the main Person class (the person class would only contain the person_id property) so I can keep with being OO by passing around objects and not primitive data types (i.e. the person_id).

--
Shawn Clark


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