-->
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.  [ 6 posts ] 
Author Message
 Post subject: hib classes, other methods?
PostPosted: Wed Dec 20, 2006 12:06 pm 
Newbie

Joined: Wed Dec 20, 2006 11:47 am
Posts: 6
3.2:

From the documentation, it seems the hibernate persistent class methods are getters/setter for table columns and relationship to other entities as reflected in its corresponding hbm.xml. Can a hibernate persistent class hold other methods (static or otherwise), examples -

1) getting a list of a particular column
2) stripping or replacing problem characters in a text string

Basically the question is can other methods exist in a hibernate persistent class besides table references and relationships to other entities.

Jennifer


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 20, 2006 12:35 pm 
Expert
Expert

Joined: Fri Aug 19, 2005 2:11 pm
Posts: 628
Location: Cincinnati
Yes they can. Though, if you use the hbm tools to generate the persistant classes then your methods will get deleted each time you regen it.

But you can get around that by using the "class-code" meta attribute to add those extra methods from the hbm.xml files orrrrrr extending the persistant class and keeping the extra methods in those.

to extend you just do somethin like:
Code:
<class
    name="package.ClassA"
    table="some_table"
>
<meta attribute="generated-class" inherit="false">package.BaseClassA</meta>



and just name the class with the extra methods ClassA which extends BaseClassA.

_________________
Chris

If you were at work doing this voluntarily, imagine what you'd want to see to answer a question.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 20, 2006 2:02 pm 
Newbie

Joined: Wed Dec 20, 2006 11:47 am
Posts: 6
Thank you for your response.

I am a newbie with hibernate, so bear with me.

How is a regular java subclassing different than a hibernate subclass?

There is another definition in the hbm.xml file that needs to be included -

<class
name="package.BaseClassA"
table="BaseClassATable"
>

ClassA hold static methods for queries and data manipulation of data from BaseClassATable, not from "some_table". There is no association of ClassA with "some_table". How can I do this?

Jennifer


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 20, 2006 2:13 pm 
Expert
Expert

Joined: Fri Aug 19, 2005 2:11 pm
Posts: 628
Location: Cincinnati
"some_table" was the table name in the database which has no effect on your extending classes.

Code:
<class
    name="org.hibernate.Apple"
    table="apple_table"
>
<meta attribute="generated-class" inherit="false">org.hibernate.BaseApple</meta>


A mapping like that of the above will take care of all the work. In the class "BaseApple" you have the regular POJO fields, setters, getters, and constructors. This is generated by hbmtools or you.

Then YOU write Apple which extends BaseApple. Apple has all of BaseApple's getters and setters, but also allows you to write extra methods in it which will use the getters and setters in BaseApple. Hibernate doesn't know you have extended classes because the class it is looking for is name="org.hibernate.Apple" and Java doesn't care if you extend classes and neither does hibernate. That meta-attribute tag in the mapping file is just in case you are using the hibernate tools to generate the POJOs from the hbm.xml files.

_________________
Chris

If you were at work doing this voluntarily, imagine what you'd want to see to answer a question.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 20, 2006 2:35 pm 
Newbie

Joined: Wed Dec 20, 2006 11:47 am
Posts: 6
Does "apple_table" have to exist?

Jennifer

PS How can I rate the post?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 20, 2006 2:42 pm 
Expert
Expert

Joined: Fri Aug 19, 2005 2:11 pm
Posts: 628
Location: Cincinnati
j2 c wrote:
Does "apple_table" have to exist?

Jennifer

PS How can I rate the post?


apple_table is the table in the database that this POJO relates to. So yes, it must exist

_________________
Chris

If you were at work doing this voluntarily, imagine what you'd want to see to answer a question.


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