-->
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: Non persistent class as an aggregate of persistent entities
PostPosted: Fri Jan 23, 2009 4:55 pm 
Newbie

Joined: Fri Jan 23, 2009 4:42 pm
Posts: 5
Hi all,

I'm trying to make a class which acts like an aggregate of persistent entities. However, I do not want this class persisted.

As an example, I'd like to have a nonpersistent class House that is made up of persistent classes Windows, Doors, and Walls. I'd like to be able to call HouseDAO.save(house) and have it save all my doors, walls, and windows.

My mental pseudo-code:

class House {

@Table(name="Door")
private Door frontDoor;
private Door backDoor;

@Table (name="wall")
private Wall wall1;

@Table (name="Window")
private Window boxWindow;

... getters and setters for each

}


But that obviously doesn't work. Should I even persue this or should I just make a HouseDAO which handles everything individually? Or create a House service to farm out to the wall, window and door DAOs? Is there a standard way of doing this? I looked at both the Repository and Aggregate Entity patterns, but they don't really seem to fit.

Any suggestions or pointers would be great.

Thanks,
Mike


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 26, 2009 3:58 pm 
Newbie

Joined: Fri Jan 23, 2009 4:42 pm
Posts: 5
So I tried seom various implementations of this and figured I'd share to help people with the same issue as well as solicit some more feedback :)


First I tried creating my wall, windows and door classes. I set them up as entities and could sucessfully persist each to the database. Then I tried to create a House class like the above post.

Then I did:

Em.persist(house);

and got an error that House wasn't an entity. Just for kicks I threw a @Entity on the house class and got a 'no id' error. Knowing where this was going, but hoping for somethign else I threw an ID in the house class, tried to save is and got errors based on not having a House table.


Is there a way to call 'persist' (or even save) on a class which isn't an entity but contains entity variables in order to persist all the variable entities?

I don't know why I'm so hung up on this. It just feels like creating having to call .persist(wall) / .persist(window) / .persist(door) each time I want to just persists the members of 'house' class without persisting the house itself is excessive. I guess for now I'll create a save method in my house which just makes those persist calls.

Any pointers - even just to general info - would be great.
Thanks,
Mike


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 27, 2009 3:43 am 
Expert
Expert

Joined: Thu Jan 08, 2009 6:16 am
Posts: 661
Location: Germany
Why do you want to store only the elements of a house, not the house itself? How are you going to reload an existing house from the database?

I recommend you to store the house as well (with Id and associations to it's elements). If you do not want to do that, than you are on the right way with implementing a save-method in your house-class, which does all persist calls. But again, this solutions seems to be inappropriate.

_________________
-----------------
Need advanced help? http://www.viada.eu


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 27, 2009 11:59 am 
Newbie

Joined: Fri Jan 23, 2009 4:42 pm
Posts: 5
I was thinking as I wasusing that the example might not be the best, but I couldn't think of a better one. I don't want to use my actual biz models.

For my example, the concept and useage of the house is only valid during run time at the point of creation and then is useless.* The structure has no reason to exist beyond the scope of a session, although all the components of that structure do.

After looking and trying several more things out (@embedded seemed promising) I believe you're right - time to just make the House call all the persist methods on its own.

Thanks :)

Mike

*EDIT
But the changes they made to the size and shape of the doors and windows etc need to be saved.


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.