-->
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.  [ 3 posts ] 
Author Message
 Post subject: How to make a foreign key (one-to-one) as my only id?
PostPosted: Thu Sep 29, 2005 8:03 am 
Regular
Regular

Joined: Mon Aug 29, 2005 9:46 am
Posts: 102
Hello everyone,

I have a class which has a association with others. Among this association, there's a one-to-one association that I wanna turn into a ID. I am getting a mapping exception, saying " Attribute "column" must be declared for element type "one-to-one"." even having the "column" declared. Please, help me find the error. My mapping document comes below:

Hibernate version: 3.0
Mapping documents:
Code:
  <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD//EN"
         "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
 
<hibernate-mapping>
    <class name="auge.bean.FichaTecnica" table="FICHATECNICA" >
       <id name="fichaTecnica" column="fichaTecnica" type="java.lang.STRING">
          <generator class="foreign">
              <param name="property">fichaTecnica</param>
          </generator>
       </id>
       <one-to-one name="fichaTecnica" column="fichaTecnica" class="auge.bean.Produto"
                    not-null="true" constrained="true" lazy="false"/>                                           
       
       
       <property name="molde" column="molde" type="java.lang.String" />
       <property name="data" column="data" type="java.util.Date" />       
       <property name="tamanhoPiloto" column="tamanhoPiloto" type="java.lang.String" />
       <property name="frenteModelo" column="frenteModelo" type="java.lang.String" />       
       <property name="costasModelo" column="costasModelo" type="java.lang.String" />             
       <property name="estilo" column="estilo" type="java.lang.String" />                           
       <property name="acabamento" column="acabamento" type="java.lang.String" />                                   
       <property name="observacao" column="observacao" type="java.lang.String" />                                         
       
       <many-to-one name="modelista" column="modelista" class="auge.bean.Pessoa"
                    not-null="false" lazy="false"/>       
                   
       <many-to-one name="pilotista" column="pilotista" class="auge.bean.Pessoa"
                    not-null="false" lazy="false"/>   
                                           
       <many-to-one name="estilista" column="estilista" class="auge.bean.Pessoa"
                    not-null="false" lazy="false"/>                       
                   
    </class>
</hibernate-mapping>


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 29, 2005 8:38 am 
Regular
Regular

Joined: Mon Aug 29, 2005 9:46 am
Posts: 102
Got a little better. Now my mapping is like this:
Code:
  <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD//EN"
         "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
 
<hibernate-mapping>
    <class name="auge.bean.FichaTecnica" table="FICHATECNICA" >
       <id name="fichaTecnica" column="fichaTecnica" type="java.lang.String">
          <generator class="foreign">
              <param name="property">fichaTecnica</param>
          </generator>
       </id>
       <one-to-one name="fichaTecnica" class="auge.bean.Produto" lazy="false"/>                                           
       
       <property name="molde" column="molde" type="java.lang.String" />
       <property name="data" column="data" type="java.util.Date" />       
       <property name="tamanhoPiloto" column="tamanhoPiloto" type="java.lang.String" />
       <property name="frenteModelo" column="frenteModelo" type="java.lang.String" />       
       <property name="costasModelo" column="costasModelo" type="java.lang.String" />             
       <property name="estilo" column="estilo" type="java.lang.String" />                           
       <property name="acabamento" column="acabamento" type="java.lang.String" />                                   
       <property name="observacao" column="observacao" type="java.lang.String" />                                         
       
       <many-to-one name="modelista" column="modelista" class="auge.bean.Pessoa"
                    not-null="false" lazy="false"/>       
                   
       <many-to-one name="pilotista" column="pilotista" class="auge.bean.Pessoa"
                    not-null="false" lazy="false"/>   
                                           
       <many-to-one name="estilista" column="estilista" class="auge.bean.Pessoa"
                    not-null="false" lazy="false"/>                       
                   
    </class>
</hibernate-mapping>



Now I get the error:
Code:
2005-09-29 09:37:37,643 DEBUG hibernate.engine.Cascades  -> id unsaved-value strategy UNDEFINED
2005-09-29 09:37:37,644 DEBUG event.def.AbstractSaveEventListener  -> generated identifier: 0011, using strategy: org.hibernate.id.ForeignGenerator
2005-09-29 09:37:37,644 DEBUG event.def.AbstractSaveEventListener  -> saving [auge.bean.FichaTecnica#0011]
2005-09-29 09:37:37,646 ERROR hibernate.property.BasicPropertyAccessor  -> IllegalArgumentException in class: auge.bean.FichaTecnica, setter method of property: fichaTecnica
2005-09-29 09:37:37,646 ERROR hibernate.property.BasicPropertyAccessor  -> expected type: auge.bean.Produto, actual value: java.lang.String
2005-09-29 09:37:37,652 DEBUG hibernate.transaction.JDBCTransaction  -> rollback


My code is giving the value as expected ( auge.bean.Produto and not java.lang.String). So I suppose hibernate is having problems because of the id type specified.

Someone, please?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 29, 2005 9:42 am 
Regular
Regular

Joined: Mon Aug 29, 2005 9:46 am
Posts: 102
mapping changed, problem changed:

Code:
  <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD//EN"
         "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
 
<hibernate-mapping>
    <class name="auge.bean.FichaTecnica" table="FICHATECNICA" >
       <id name="fichaTecnica" column="fichaTecnica" type="java.lang.String">
          <generator class="assigned">
              <param name="property">fichaTecnica</param>
          </generator>
       </id>
       <one-to-one name="fichaTecnica" class="auge.bean.Produto" lazy="false"/>                                           
       
       <property name="molde" column="molde" type="java.lang.String" />
       <property name="data" column="data" type="java.util.Date" />       
       <property name="tamanhoPiloto" column="tamanhoPiloto" type="java.lang.String" />
       <property name="frenteModelo" column="frenteModelo" type="java.lang.String" />       
       <property name="costasModelo" column="costasModelo" type="java.lang.String" />             
       <property name="estilo" column="estilo" type="java.lang.String" />                           
       <property name="acabamento" column="acabamento" type="java.lang.String" />                                   
       <property name="observacao" column="observacao" type="java.lang.String" />                                         
       
       <many-to-one name="modelista" column="modelista" class="auge.bean.Pessoa"
                    not-null="false" lazy="false"/>       
                   
       <many-to-one name="pilotista" column="pilotista" class="auge.bean.Pessoa"
                    not-null="false" lazy="false"/>   
                                           
       <many-to-one name="estilista" column="estilista" class="auge.bean.Pessoa"
                    not-null="false" lazy="false"/>                       
                   
    </class>
</hibernate-mapping>



I changed it to assigned. Now i get no error, but the thing doesn't work. After calling "save", it loses itself. On the log I get:
Code:
2005-09-29 10:36:46,548 DEBUG event.def.AbstractFlushingEventListener  -> executing flush
2005-09-29 10:36:46,548 DEBUG event.def.AbstractFlushingEventListener  -> post flush
2005-09-29 10:36:46,549 DEBUG hibernate.jdbc.JDBCContext  -> before transaction completion
2005-09-29 10:36:46,549 DEBUG hibernate.impl.SessionImpl  -> before transaction completion
2005-09-29 10:36:46,552 DEBUG hibernate.transaction.JDBCTransaction  -> committed JDBC Connection
2005-09-29 10:36:46,553 DEBUG hibernate.jdbc.JDBCContext  -> after transaction completion
2005-09-29 10:36:46,553 DEBUG hibernate.impl.SessionImpl  -> after transaction completion
2005-09-29 10:36:46,555 DEBUG hibernate.impl.SessionImpl  -> closing session
2005-09-29 10:36:46,555 DEBUG hibernate.jdbc.ConnectionManager  -> closing JDBC connection [ (open PreparedStatements: 0, globally: 0) (open ResultSets: 0, globally: 0)]
2005-09-29 10:36:46,555 DEBUG hibernate.jdbc.JDBCContext  -> after transaction completion
2005-09-29 10:36:46,556 DEBUG hibernate.impl.SessionImpl  -> after transaction completion


All I need is to know the right way to do it. Someone please?


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