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.  [ 1 post ] 
Author Message
 Post subject: hbm.xml vs. annotations
PostPosted: Wed Feb 21, 2007 5:19 pm 
Newbie

Joined: Wed Feb 21, 2007 4:03 pm
Posts: 1
Currently, I have a class which contains a set of String objects from a child table. All of the examples that I've seen only show the xml version of this setup, and using the hbm.xml file, this is working just fine.

I would like to move entirely to annotations, but haven't found an equivalent way of specifying which database column to use in the annotations (the element/column/type section of set in the xml).

When I attempt to run without the hbm.xml, the logs complain about a missing "column" since the "element" isn't defined.

Is there a way of doing this with Hibernate specific annotations? Or am I stuck with the hbm.xml files for now?

Thanks.


Hibernate version:
Hibernate EntityManager 3.2.1.GA
Hibernate Annotations 3.2.1.GA

App Server version:
JBoss [Zion] 4.0.4.GA (build: CVSTag=JBoss_4_0_4_GA date=200605151000)

Mapping documents:
Inventory.hbm.xml
Code:
<hibernate-mapping>
    <class name="some.package.Inventory" table="Inventory">

        <id name="myId" type="long" column="inventory_id">
            <generator class="sequence"/>
        </id>

        <!-- other <property elements for other columns, etc... -->

        <set name="myApplications" table="inventory_applications" cascade="all">
            <key column="inventory_id"/>
            <element column="app_name" type="string"/>
        </set>
    </class>
</hibernate-mapping>


Java File
Code:
@Entity
@Table(name="Inventory")
public class Inventory
    implements Serializable
{
    private long myId;
    private Set<String> myApplications = new HashSet<String>(0);

    ...snip simple getters/setters/field declarations ...

    @CollectionOfElements()
    @JoinTable(name="inventory_applications", joinColumns = {
        @JoinColumn(name="inventory_id", nullable=false, updatable=false) })
    public Set<String> getMyApplications() {
        return this.myApplications;
    }

    public void setMyApplications(Set<String> myApplications) {
        this.myApplications = myApplications;
    }
}


Simplified Database Schema
Code:
INVENTORY
=========
inventory_id (long - pk)
** other columns **

INVENTORY_APPLICATIONS
========================
inventory_id (long - fk - nonunique)
app_name (string)


Full stack trace of any exception that occurs:
Caused by: org.postgresql.util.PSQLException: ERROR: column myapplicat2_.element does not exist
at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:1512)
at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1297)
at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:188)
at org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:430)
at org.postgresql.jdbc2.AbstractJdbc2Statement.executeWithFlags(AbstractJdbc2Statement.java:346)
at org.postgresql.jdbc2.AbstractJdbc2Statement.executeQuery(AbstractJdbc2Statement.java:250)
at org.jboss.resource.adapter.jdbc.CachedPreparedStatement.executeQuery(CachedPreparedStatement.java:90)
at org.jboss.resource.adapter.jdbc.WrappedPreparedStatement.executeQuery(WrappedPreparedStatement.java:236)
at org.hibernate.jdbc.AbstractBatcher.getResultSet(AbstractBatcher.java:186)
at org.hibernate.loader.Loader.getResultSet(Loader.java:1778)
at org.hibernate.loader.Loader.doQuery(Loader.java:662)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:224)
at org.hibernate.loader.Loader.doList(Loader.java:2211)
... 42 more

Name and version of the database you are using:
RDBMS: PostgreSQL, version: 8.1.3
JDBC driver: PostgreSQL Native Driver, version: PostgreSQL 8.1 JDBC3 with SSL (build 404)


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.