-->
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: Problem using Hibernate CompositeUserType
PostPosted: Sun Apr 10, 2011 9:58 am 
Beginner
Beginner

Joined: Mon Sep 20, 2010 2:35 am
Posts: 20
Hi All,

I am trying to use HibernateCompositeUser type to handle i18n specific data in my application. i am trying to use the below approach.

I have a table named master table which contains all locale independent data while i have created another table master_translation which contains all locale sensitive information. Master table contains a reference to the master_translation.here is the detailed table structure

Code:
master
---ID
---master_translation
---Other locale independent fields.

master_translation
---ID
---language_id
---Other locale sensitive fields


now i am using HibernateCompositeUser type to handle this internal process. here is the mapping for master class.

Code:
<hibernate-mapping>
    <class name="Master"
        table="MASTER">
        <id name="uuid" type="java.lang.String">
            <column name="UUID" />
            <generator class="uuid" />
        </id>

        <property name="master_i18n" type="masteri18n">
           <column name="NAME"/>
           <column name="SHORTDESCRIPTION"/>
           <column name="LONGDESCRIPTION"/>
    </class>
</hibernate-mapping>


where type="masteri18n" is hibernate CompositeUserType.now when i am fetching the master content it is correctly fetching the data based on the language and my Master class contain a reference to the Master_translation which holding locale specific data. Problem getting started when i am trying to insert the data in to the respectice tables.Here is a code snap shot from the CompositeUserType

Code:
@Override
    public void nullSafeSet(PreparedStatement ps, Object arg1, int index,
            SessionImplementor arg3) throws HibernateException, SQLException {

        if(arg1==null){
            //need to handle this case
        }
        else{
             Master_i18n mas=(Master_i18n)arg1;
             //ps.setString(index,mas.getName());
             mas=dao.saveMaster_i18n(mas);
             Hibernate.STRING.nullSafeSet(ps, mas.getUuid(), index);
            //ps.setString(index+1, mas.getShortDescription());
            //ps.setString(index+2, mas.getLongDescription());
            //ps.setString(index+3, mas.getLanguage_id());

        }
    }


what i am trying to do is first saving my Master_i18n and den set it reference in to the Master Though Master_i18n getting saved properly but when it comes to the Master itself hibernate is creating SQL for all the fields which are defined in the Master_i18n
Code:
insert
        into
            poc.Master
            (NAME, SHORTDESCRIPTION, LONGDESCRIPTION, UUID)
        values
            (?, ?, ?, ?)


and finally its throwing the following exception
Code:
Caused by: java.sql.SQLException: No value specified for parameter 2
    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1075)
    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:989)
    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:984)
    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:929)
    at com.mysql.jdbc.PreparedStatement.checkAllParametersSet(PreparedStatement.java:2560)
    at com.mysql.jdbc.PreparedStatement.addBatch(PreparedStatement.java:1015)
    at org.hibernate.jdbc.BatchingBatcher.addToBatch(BatchingBatcher.java:53)


i have just started getting familiar with Custom mapping type so not sure what exactly i am doing wrong. Any help/pointer in this regard will be much helpful.


Top
 Profile  
 
 Post subject: Re: Problem using Hibernate CompositeUserType
PostPosted: Mon Apr 11, 2011 10:44 am 
Beginner
Beginner

Joined: Mon Sep 20, 2010 2:35 am
Posts: 20
Any suggestion as i am also struck here and not sure how to move forward


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.