-->
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: Polymorphic property
PostPosted: Thu Jan 05, 2006 9:31 am 
Newbie

Joined: Thu Jan 05, 2006 9:20 am
Posts: 5
I vave a class Instruction that is mapped to an INSTRUCTION table.
The class instruction has a property that is a state. I want this state to be a class herarchy that has its own behavior depending on the specific instance.
how can I make hibernate instanciate the appropied instance based on the value of the state field in the INSTRUCTION table.
Note that State is not a persistent class so it has no mapping of its own.
State is like a Component or a custom type that has to be instanciated by hibernate on the base of a field value in a table.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 09, 2006 9:35 am 
Expert
Expert

Joined: Tue Nov 23, 2004 7:00 pm
Posts: 570
Location: mostly Frankfurt Germany
Hello,

you could take a different approach.
Define state as a component holding an identifier.
Your state Class could call a factory depending on the value of the field. So the method of your State class does not implement the behaviour itself but call the Logic class generated by the factory.

Please rate, if this helped.
Regards Sebastian

_________________
Best Regards
Sebastian
---
Training for Hibernate and Java Persistence
Tutorials for Hibernate, Spring, EJB, JSF...
eBook: Hibernate 3 - DeveloperGuide
Paper book: Hibernate 3 - Das Praxisbuch
http://www.laliluna.de


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 09, 2006 9:44 am 
Newbie

Joined: Thu Jan 05, 2006 9:20 am
Posts: 5
Thanks,

Actually I did allready take that approach. Except that y just left the state as a text field and called the fabric from the INSTRUCTION entity. Actually is the same, thanks anyway.

Besides, it would be nice to be able to subclass components and propertyes. Could this be asked as a feature in hibernate ?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 09, 2006 9:48 am 
Expert
Expert

Joined: Tue Nov 23, 2004 7:00 pm
Posts: 570
Location: mostly Frankfurt Germany
This is allready implemented. You can define custom types. See the examples for Hibernate Caveatemp...

_________________
Best Regards
Sebastian
---
Training for Hibernate and Java Persistence
Tutorials for Hibernate, Spring, EJB, JSF...
eBook: Hibernate 3 - DeveloperGuide
Paper book: Hibernate 3 - Das Praxisbuch
http://www.laliluna.de


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 09, 2006 9:57 am 
Newbie

Joined: Thu Jan 05, 2006 9:20 am
Posts: 5
I know that you can define custome types. But I mean what I was asking before. That you could map an interface as a component or property and hibernate would instanciate the concrete class based on a discriminator field in tha main table.


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.