-->
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: "Typed one-to-one association", schema export fail
PostPosted: Mon Dec 22, 2008 11:19 am 
Newbie

Joined: Mon Dec 22, 2008 6:02 am
Posts: 1
Hibernate version: 3.3.1.GA

Name and version of the database you are using: MySQL 5.0.67-community-nt (with driver mysql-connector-java-5.1.7-bin.jar)


I need to use what is called a "typed one-to-one association". Here are my classes (omitted packages/imports/getters/setters):

Code:
public class Proposal implements Serializable {
    private Long proposalId;
    private Contract contract;
    // ... getters/setters ...
}

Code:
public class Contract implements Serializable {
    private String name;
    private Address legalSitusAddress;
    private Address shipmentAddress;
    private Address mailAddress;
    // ... getters/setters ...
}

Code:
public class Address implements Serializable {
    private Long proposalId;
    private String addressType;
    private String street;
    private String number;
    // ... getters/setters ...
}


Note, Contract is a "component" (value type).

There is an example of "typed one-to-one association" in the Hibernate reference here: http://www.hibernate.org/hib_docs/v3/reference/en-US/html/misc.html#example-mappings-typed-onetone

It seems quite easy to understand and so, watching the example, I have created the following mappings:

Code:
<hibernate-mapping package="hibtester.model">
  <class name="Proposal" table="PROPOSALS">
    <id name="proposalId" column="PROPOSAL_ID">
      <generator class="native"/>
    </id>

    <component name="contract" class="Contract">
      <property name="name" column="NAME" length="50" not-null="false"/>

      <one-to-one name="legalSitusAddress" cascade="all">
        <formula>proposalId</formula>
        <formula>'LE'</formula>
      </one-to-one>

      <one-to-one name="shipmentAddress" cascade="all">
        <formula>proposalId</formula>
        <formula>'SH'</formula>
      </one-to-one>

      <one-to-one name="mailAddress" cascade="all">
        <formula>proposalId</formula>
        <formula>'MA'</formula>
      </one-to-one>
    </component>
  </class>
</hibernate-mapping>

Code:
<hibernate-mapping package="hibtester.model">
  <class name="Address" table="ADDRESSES">
    <composite-id>
      <key-many-to-one name="proposalId" column="PROPOSAL_ID"/>
      <key-property name="addressType" column="ADDRESS_TYPE" length="2"/>
    </composite-id>

    <property name="street" column="STREET" length="50" not-null="false"/>
    <property name="number" column="NUMBER" length="4" not-null="false"/>
  </class>
</hibernate-mapping>


There are some differences from the example: I have 3 addresses and they are in a component. But I think it's not this the problem.

Trying to create the schema using schema export Ant task I get:

Code:
schema:

BUILD FAILED
C:\...........\build.xml:76: Schema text failed: An association from the table ADDRESSES refers to an unmapped class: java.lang.Long


It's not clear to me the problem and how to resolve it. I have used Long type for ids and normal fields in other projects without problems.

Log at trace level using log4j seems not to help:

Code:
15:55:50,406  INFO Environment:543 - Hibernate 3.3.1.GA
15:55:50,421  INFO Environment:576 - hibernate.properties not found
15:55:50,421  INFO Environment:709 - Bytecode provider name : javassist
15:55:50,421  INFO Environment:627 - using JDK 1.4 java.sql.Timestamp handling
15:55:50,500  INFO Configuration:1494 - configuring from file: hibernate.cfg.xml
15:55:50,546 DEBUG DTDEntityResolver:64 - trying to resolve system-id [http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd]
15:55:50,546 DEBUG DTDEntityResolver:66 - recognized hibernate namespace; attempting to resolve on classpath under org/hibernate/
15:55:50,546 DEBUG DTDEntityResolver:76 - located [http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd] in classpath
15:55:50,593 DEBUG Configuration:1421 - connection.driver_class=com.mysql.jdbc.Driver
15:55:50,593 DEBUG Configuration:1421 - connection.url=jdbc:mysql://localhost/hibtester
15:55:50,593 DEBUG Configuration:1421 - connection.username=root
15:55:50,593 DEBUG Configuration:1421 - connection.password=.
15:55:50,593 DEBUG Configuration:1421 - connection.pool_size=1
15:55:50,593 DEBUG Configuration:1421 - dialect=org.hibernate.dialect.MySQLDialect
15:55:50,593 DEBUG Configuration:1421 - current_session_context_class=thread
15:55:50,593 DEBUG Configuration:1421 - cache.provider_class=org.hibernate.cache.NoCacheProvider
15:55:50,593 DEBUG Configuration:1421 - show_sql=true
15:55:50,593 DEBUG Configuration:1421 - format_sql=true
15:55:50,593 DEBUG Configuration:1620 - null<-org.dom4j.tree.DefaultAttribute@acb158 [Attribute: name resource value "hibtester/model/Proposal.hbm.xml"]
15:55:50,593  INFO Configuration:586 - Reading mappings from resource : hibtester/model/Proposal.hbm.xml
15:55:50,593 DEBUG DTDEntityResolver:64 - trying to resolve system-id [http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd]
15:55:50,593 DEBUG DTDEntityResolver:66 - recognized hibernate namespace; attempting to resolve on classpath under org/hibernate/
15:55:50,593 DEBUG DTDEntityResolver:76 - located [http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd] in classpath
15:55:50,687  INFO HbmBinder:322 - Mapping class: hibtester.model.Proposal -> PROPOSALS
15:55:50,703 DEBUG HbmBinder:1289 - Mapped property: proposalId -> PROPOSAL_ID
15:55:50,718 DEBUG HbmBinder:1289 - Mapped property: name -> NAME
15:55:50,718 DEBUG HbmBinder:1289 - Mapped property: legalSitusAddress -> proposalId, 'LE'
15:55:50,718 DEBUG HbmBinder:1289 - Mapped property: shipmentAddress -> proposalId, 'SH'
15:55:50,718 DEBUG HbmBinder:1289 - Mapped property: mailAddress -> proposalId, 'MA'
15:55:50,718 DEBUG HbmBinder:1289 - Mapped property: contract -> NAME, proposalId, 'LE', proposalId, 'SH', proposalId, 'MA'
15:55:50,718 DEBUG Configuration:1620 - null<-org.dom4j.tree.DefaultAttribute@737371 [Attribute: name resource value "hibtester/model/Address.hbm.xml"]
15:55:50,718  INFO Configuration:586 - Reading mappings from resource : hibtester/model/Address.hbm.xml
15:55:50,718 DEBUG DTDEntityResolver:64 - trying to resolve system-id [http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd]
15:55:50,718 DEBUG DTDEntityResolver:66 - recognized hibernate namespace; attempting to resolve on classpath under org/hibernate/
15:55:50,718 DEBUG DTDEntityResolver:76 - located [http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd] in classpath
15:55:50,750  INFO HbmBinder:322 - Mapping class: hibtester.model.Address -> ADDRESSES
15:55:50,812 DEBUG HbmBinder:1289 - Mapped property: proposalId -> PROPOSAL_ID
15:55:50,812 DEBUG HbmBinder:1289 - Mapped property: addressType -> ADDRESS_TYPE
15:55:50,812 DEBUG HbmBinder:1289 - Mapped property: street -> STREET
15:55:50,812 DEBUG HbmBinder:1289 - Mapped property: number -> NUMBER
15:55:50,812  INFO Configuration:1575 - Configured SessionFactory: null
15:55:50,828 DEBUG Configuration:1576 - properties: {.....long list.....}
15:55:50,843  INFO Dialect:175 - Using dialect: org.hibernate.dialect.MySQLDialect
15:55:50,843 DEBUG Configuration:1153 - processing extends queue
15:55:50,843 DEBUG Configuration:1157 - processing collection mappings
15:55:50,843 DEBUG Configuration:1168 - processing native query and ResultSetMapping mappings
15:55:50,843 DEBUG Configuration:1176 - processing association property references
15:55:50,843 DEBUG Configuration:1198 - processing foreign key constraints
15:55:50,843 DEBUG Configuration:1281 - resolving reference to class: java.lang.Long



Any help is appreciated. Thanks.


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.