Hibernate fails to lookup name on annotated id

I am building a Java EE application using hibernate to map database entities. Server is JBoss 5.2. In my application I created the entity X, which has two ints as primary keys.

@Entity
@Table(name = "X")
@NamedQueries({
    @NamedQuery(name = "findByMyId", query = "select o from X o where o.id = :id")
})
@IdClass(XPK.class)
public class X implements Serializable {

    private int id, version;

    @Id
    @Column(name = "VERSION_NUMBER", unique = false, nullable = false)
    public int getVersion() {
        return version;
    }

    public void setVersion(int v) {
        version = v;
    }

    @Id
    @Column(name = "MY_ID", unique = false, nullable = false)
    public int getId() {
        return id;
    }

    public void setId(int i) {
        id = i;
    }
}

The private key class is pretty straight forward. It contains the id:s with the same names, getters, and setters as in the entity.

public class XPK {

    private int id, version;


    public XPK() {}

    public XPK(int i, int v) {
        id = i;
        version = v;
    }

    public int getVersion() {
        return version;
    }

    public void setVersion(int v) {
        version = v;
    }

    public int getId() {
        return id;
    }

    public void setId(int i) {
        id = i;
    }
}

Persistence-unit looks like this:

<property name="hibernate.cache.use_second_level_cache" value="true"/>
<property name="hibernate.cache.use_query_cache" value="true"/>
<property name="hibernate.cache.region.factory_class" value="org.hibernate.cache.jbc2.JndiMultiplexedJBossCacheRegionFactory"/>
<property name="hibernate.cache.region.jbc2.cachefactory" value="java:CacheManager"/>
<property name="hibernate.cache.region.jbc2.cfg.entity" value="mvcc-entity"/>
<property name="hibernate.cache.region.jbc2.cfg.query" value="local-query"/>
<property name="hibernate.show_sql" value="false"/>
<property name="hibernate.session_factory_name" value="BaseModelSessionFactory"/>
<property name="hibernate.generate_statistics" value="true"/>
<property name="hibernate.use_sql_comments" value="true"/>

I would like the id columns to have other names than id and version (namely MY_ID and VERSION_NUMBER), as this is what they are named in the database. When I start the JBoss it complains that it cannot find an error with "ID": invalid identifier. How can this happen, I feel that the @Column(name) should do the trick?

Note: No spring is used.

Answers


First of all XPK must implement Serializable.

Have a look at the tutorial: http://docs.oracle.com/cd/E16439_01/doc.1013/e13981/cmp30cfg001.htm

Can you please provide the stack trace?


Need Your Help

Download all Maven plugins

java maven-2

Is there an easy way to download all the official Maven plugins (http://maven.apache.org/plugins/index.html) with one command?

Error in SQL script file

sql sql-server

I am working on a database and we are trying to make a script file that will give us the total number of orders in july.