-->
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.  [ 16 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: hbm2java ignores name attribute in property
PostPosted: Wed Feb 11, 2009 10:21 am 
Newbie

Joined: Wed Feb 11, 2009 9:42 am
Posts: 9
I want to create Java classes with the hbm2java function of Hibernate Tools and get a problem with the name attribute in property.

Code:
...
<property
   name="Title"
   column="title"
   type="string"
   not-null="false"
   length="255"
/>
...


becomes

Code:
...
private String title;
...
@Column(name="title")
public String getTitle() {
   return this.Title;
}
...


If an query contains "... where Class.title = :searchTitle", it works, but not with "... where Class.Title = :searchTitle".
The hbm file renames the property, but in annotations something like this is missing.
Is there something I have setup in the Hibernate Tools?
Is renaming properties possible in Hibernate Annotations?
What would i have to change in the annotations by myself to get renaming?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 13, 2009 5:25 am 
Newbie

Joined: Wed Feb 11, 2009 9:42 am
Posts: 9
Any suggestions?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 13, 2009 6:14 am 
Expert
Expert

Joined: Fri Jan 30, 2009 1:47 am
Posts: 292
Location: Bangalore, India
"... where Class.Title = :searchTitle"
Well this query is not supposed to run if your property name is title. Coz in HQL property names and Class names are case-sensitive.

_________________
Regards,
Litty Preeth


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 13, 2009 6:19 am 
Newbie

Joined: Wed Feb 11, 2009 9:42 am
Posts: 9
littypreethkr wrote:
"... where Class.Title = :searchTitle"
Well this query is not supposed to run if your property name is title. Coz in HQL property names and Class names are case-sensitive.


Yes, I know. But inside hbm files it is possible to "rename" the column name in database to an other name for the HQL.
I want to know if there is a similar way with Hibernate Annotations.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 13, 2009 6:27 am 
Expert
Expert

Joined: Fri Jan 30, 2009 1:47 am
Posts: 292
Location: Bangalore, India
Are you talking about the "column" attribute of the "property" tag? If so @Column is the annotation counter part.

But I feel you are meaning something else. If so can you tell me how you
Iacturus wrote:
"rename" the column name in database to an other name for the HQL

_________________
Regards,
Litty Preeth


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 13, 2009 6:39 am 
Newbie

Joined: Wed Feb 11, 2009 9:42 am
Posts: 9
No, I talk about the "name" attribute of the "property" tag in the hbm file.
Like:
Code:
<property
   name="Title"
   column="title"
   type="string"
   not-null="false"
   length="255"
/>

The column attribute is the name of the colum inside the database.
The name attribute is the name which is used inside HQL queries.
For that name attribute, I did not found the annotation counter part.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 13, 2009 6:46 am 
Expert
Expert

Joined: Fri Jan 30, 2009 1:47 am
Posts: 292
Location: Bangalore, India
Well while using annotations hibernate will take the name of the field as the name of the property.

<property name="title" column="T_TITLE" type="java.lang.String"/>

@Column(name="T_TITLE") ---> Equivalent to the column attribute
String title; ---> Equivalent to the name attribute
|
|------------------------> Equivalent to the type attribute

Hope this clears your doubt.

_________________
Regards,
Litty Preeth


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 13, 2009 7:14 am 
Newbie

Joined: Wed Feb 11, 2009 9:42 am
Posts: 9
Hmm...
It does not work like you explained it for me. In my java class is written:
Code:
String Title;

That mean, that a query like "... where Class.Title = :searchTitle" should work, if I understood you right. But it does not work and I get the error "could not resolve property: Title".
So either it works otherwise or I made mistake somewhere.

Btw. as I used hbm2java, the annotations are written above the getter methods inside my java classes and not above the declaration of the variables. Involes this anything special?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 13, 2009 7:47 am 
Expert
Expert

Joined: Fri Jan 30, 2009 1:47 am
Posts: 292
Location: Bangalore, India
The mistake you did is to name Title with an initial caps, in java beans the property names are supposed to start with a lower case letter.

_________________
Regards,
Litty Preeth


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 13, 2009 7:58 am 
Newbie

Joined: Wed Feb 11, 2009 9:42 am
Posts: 9
littypreethkr wrote:
The mistake you did is to name Title with an initial caps, in java beans the property names are supposed to start with a lower case letter.

As u said it used supposed to be, but it does not have to.
And it was not me who named it "Title" in Java, it was the hbm2java Tool.

The whole problem is, that I used hbm files until now in my project, where the renaming works and ALL HQL queries are written in that way. But now I want to switch to Hibernate Annotations. So it seems, that I have to rewrite all my HQL queries or find a way to rename the properties with Hibernate Annotations. But the last thing does not seem to be possible. Right?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 13, 2009 8:02 am 
Expert
Expert

Joined: Fri Jan 30, 2009 1:47 am
Posts: 292
Location: Bangalore, India
Iacturus wrote:
And it was not me who named it "Title" in Java, it was the hbm2java Tool.

The hbm2java named it "Title" because your hbm xml named it "Title"
<property
name="Title"
column="title"
type="string"
not-null="false"
length="255"
/>

_________________
Regards,
Litty Preeth


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 13, 2009 8:08 am 
Newbie

Joined: Wed Feb 11, 2009 9:42 am
Posts: 9
littypreethkr wrote:
Iacturus wrote:
And it was not me who named it "Title" in Java, it was the hbm2java Tool.

The hbm2java named it "Title" because your hbm xml named it "Title"


Yes, I know that.
But my old queries do not work with the annotations generated by hbm2java, but they work with the hbms. I am looking for a way how I do not have to rewrite all my queries while using annotations.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 13, 2009 8:12 am 
Expert
Expert

Joined: Fri Jan 30, 2009 1:47 am
Posts: 292
Location: Bangalore, India
Iacturus wrote:
I am looking for a way how I do not have to rewrite all my queries while using annotations.

You will either have to re-write your queries or you will have to make T caps manually in the generated pojo file.

_________________
Regards,
Litty Preeth


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 13, 2009 8:18 am 
Newbie

Joined: Wed Feb 11, 2009 9:42 am
Posts: 9
/doublepost


Last edited by Iacturus on Fri Feb 13, 2009 8:21 am, edited 2 times in total.

Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 13, 2009 8:18 am 
Newbie

Joined: Wed Feb 11, 2009 9:42 am
Posts: 9
littypreethkr wrote:
.. you will have to make T caps manually in the generated pojo file.


Do you mean "String Title"? hbm2java generated it with T caps, but it does not work... thats my problem ^^


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 16 posts ]  Go to page 1, 2  Next

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.