-->
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.  [ 2 posts ] 
Author Message
 Post subject: JPA annotations: Can't map one column ***SOLVED***
PostPosted: Wed Oct 02, 2013 7:26 pm 
Beginner
Beginner

Joined: Mon Jul 28, 2008 4:36 pm
Posts: 24
I'm almost positive that this is a mapping/annotation problem, but I'm at a total loss as to how to fix it. I have a few hundred columns mapped properly. 2 are not working. Those two had the same name, but now I've renamed one of them and it still has the same problem, so the naming similarity is just a coincidence.

table_a has a field with the following signature (notice two 'n's misspelling) (BROKEN):
Code:
`num_anncestors` int(11) NOT NULL


For reference, table_c has the following column which WORKS:
Code:
`password_life_days` int(11) NOT NULL


Yesterday, when I used Hibernate .hbm.xml files this wasn't a problem. I just converted to JPA annotations and everything else seems to be working, even the other columns of these same tables. Just reading this one column has no effect and referencing it in a criteria query produces: "org.hibernate.QueryException: could not resolve property: numAnncestors of: TableA". I haven't updated anything to use the JPA EntityManager instead of Hibernate.Session.

Here are the (new) mappings BROKEN:
Code:
@javax.persistence.Entity
@Table(name="table_a"
    ,catalog="mydb"
)
public class TableA implements java.io.Serializable {
...
    @Column(name="num_anncestors", nullable=false)
    @Override
    public int numAnncestors() { return numAnncestors; }
    public void setNumAnncestors(int x) { numAnncestors = x; }
...


TableC WORKS:
Code:
@javax.persistence.Entity
@Table(name="table_c"
    ,catalog="mydb"
    , uniqueConstraints = @UniqueConstraint(columnNames="identifier_c")
)
public class TableC implements java.io.Serializable {
...
    @Column(name="password_life_days", nullable=false)
    public int getPasswordLifeDays() { return passwordLifeDays; }
    public void setPasswordLifeDays(int x) { passwordLifeDays = x; }
...


When I try to do a criteria query, I get an exception:
Code:
// This used to work, but now I get:
// org.hibernate.QueryException: could not resolve property: numAnncestors of: TableA
crit.add(Restrictions.eq("numAnncestors", 0),

// This doesn't work either:
// org.hibernate.QueryException: could not resolve property: TableA of: TableA
crit.add(Restrictions.eq("TableA.numAnncestors", 0),

// This doesn't work either:
// org.hibernate.QueryException: could not resolve property: TableA of: TableA
crit.createAlias("TableA", "a");
crit.add(Restrictions.eq("a.numAnncestors", 0),


I just set up my "datasource" in IDEA 12 and the inspections are not showing any warnings or issues. If I map a column wrong, they show an error. When I correct it, the error goes away. I feel out of ideas, which is unusual for me.

I had originally suspected that having a column with the same name in another table was causing an issue, but I have renamed the column so that's not the case any more (misspelled anNcestors).

Database is MySQL 5.1
Java7
Hibernate 3.6.10
Ubuntu 12.04 64-bit


Last edited by glenpeterson on Thu Oct 03, 2013 2:07 pm, edited 1 time in total.

Top
 Profile  
 
 Post subject: Re: JPA annotations: Can't map one column - worked with .hbm.xml
PostPosted: Thu Oct 03, 2013 2:06 pm 
Beginner
Beginner

Joined: Mon Jul 28, 2008 4:36 pm
Posts: 24
I solved my own problem with a little help from TomTom on #hibernate on Freenode.

Notice that the method name numAnncestors() does not start with a "get"? I had done a search-and-replace rename without realizing it had affected a persistent field. Doh!


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