-->
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.  [ 5 posts ] 
Author Message
 Post subject: Problem with <id> mapping for a view
PostPosted: Fri Jan 30, 2009 4:20 am 
Expert
Expert

Joined: Fri Jan 30, 2009 1:47 am
Posts: 292
Location: Bangalore, India
Hibernate version: 3.3.0SP1

Name and version of the database you are using:H2DB

Hi,

I am having a view ROUTERLINK which is a join of different tables like:
ROUTERID from ROUTER.ID (PK of ROUTER table)
CUSTOMERID from COUSTOMER.ID (PK of CUSTOMER table) and
SITEID from SITE.ID (PK of SITE table)


In this view ROUTERID is going to be the unique column.

ROUTERLINK mapped to CERouterBO class
ROUTER mapped to RouterBO class
CUSTOMER mapped to CustomerBO and
SITE mapped to SiteBO


The hibernate mapping I wrote for ROUTERLINK is:
Code:
<class name="CERouterBO"
      table="ROUTERLINK">
      <cache usage="read-write" />

      <id name="routerId" column="ROUTERID">
         <generator class="foreign">
            <param name="property">routerId</param>
         </generator>
      </id>
      
      <one-to-one name="routerId"
         class="RouterBO" constrained="true" />
      
      <many-to-one name="customerId"
         class="CustomerBO"
         cascade="none" fetch="join" lazy="false" access="property"
         column="CUSTOMERID" />
      <many-to-one name="siteId"
         class="SiteBO"
         cascade="none" fetch="join" lazy="false" access="property"
         column="SITEID" />
</class>


But I am getting the following exception:
java.lang.Exception: org.hibernate.HibernateException: Wrong column type in EVPN.PUBLIC.TWVROUTERLINK for column ROUTERID. Found: bigint, expected: binary(255)
at com.infovista.vistamart.evpn.server.util.ServiceLocator.initHibernate(ServiceLocator.java:106)
at com.infovista.vistamart.evpn.server.util.ServiceLocator.getHibernateSessionFactory(ServiceLocator.java:87)
at com.infovista.vistamart.evpn.server.util.HibernateUtil.getSession(HibernateUtil.java:32)
at com.infovista.vistamart.evpn.server.util.HibernateUtil.getSession(HibernateUtil.java:22)
at com.infovista.vistamart.evpn.server.dao.HibernateHandler.save(HibernateHandler.java:119)
at com.infovista.vistamart.evpn.server.dao.DBInitializer.createLookUpValues(DBInitializer.java:234)
at com.infovista.vistamart.evpn.server.dao.DBInitializer.startH2Servers(DBInitializer.java:96)
at com.infovista.vistamart.evpn.server.util.AppInitializer.contextInitialized(AppInitializer.java:43)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:3764)
at org.apache.catalina.core.StandardContext.start(StandardContext.java:4216)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:760)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:740)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:544)
at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:831)
at org.apache.catalina.startup.HostConfig.deployWARs(HostConfig.java:720)
at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:490)
at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1149)
at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:311)
at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:120)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1022)
at org.apache.catalina.core.StandardHost.start(StandardHost.java:736)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1014)
at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:443)
at org.apache.catalina.core.StandardService.start(StandardService.java:448)
at org.apache.catalina.core.StandardServer.start(StandardServer.java:700)
at org.apache.catalina.startup.Catalina.start(Catalina.java:552)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:295)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:433)

Please let me know what I am doing wrong.

Thanks n Regards,
Litty Preeth[/code]


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jan 30, 2009 4:58 am 
Senior
Senior

Joined: Thu Jan 08, 2009 3:48 pm
Posts: 168
try setting type=typename for the id

Quote:
typename could be:
1. The name of a Hibernate basic type (eg. integer, string, character,
date, timestamp, float, binary, serializable, object, blob).
2. The name of a Java class with a default basic type (eg. int, float, char,
java.lang.String, java.util.Date, java.lang.Integer, java.sql.Clob).


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jan 30, 2009 6:37 am 
Expert
Expert

Joined: Fri Jan 30, 2009 1:47 am
Posts: 292
Location: Bangalore, India
Hi pkleindl,

If I set the type as RouterBO then I get the same "Wrong column type" error. If I set the type as long then this error doesnt come, but if I make any queries to this view then I get the exception:
org.hibernate.PropertyAccessException: IllegalArgumentException occurred while calling setter of com.infovista.vistamart.evpn.client.model.CERouterBO.routerId
at org.hibernate.property.BasicPropertyAccessor$BasicSetter.set(BasicPropertyAccessor.java:104)

This I understand that I have declared RouterBO as the type of routerId attribute in my bean, but actually its a trying to set a long value into it. But I want the attribute as RouterBO only coz this is a Foreign key also which references the ROUTER table.

I could solve this by adding a long attribute "id" also to the CERouterBO class and mapped this field as the <id>; like:
Code:
   <class name="com.infovista.vistamart.evpn.client.model.CERouterBO"
      table="TWVROUTERLINK">
      <cache usage="read-write" />

      <id name="id" column="ROUTERID">
         <generator class="foreign">
            <param name="property">routerId</param>
         </generator>
      </id>

      <one-to-one name="routerId"
         class="com.infovista.vistamart.evpn.client.model.RouterBO"
         constrained="true" lazy="false" />

      <many-to-one name="customerId"
         class="com.infovista.vistamart.evpn.client.model.CustomerBO"
         cascade="none" fetch="join" lazy="false" access="property"
         column="CUSTOMERID" />
      <many-to-one name="siteId"
         class="com.infovista.vistamart.evpn.client.model.SiteBO"
         cascade="none" fetch="join" lazy="false" access="property"
         column="SITEID" />
   </class>


Is this the right approach?

Regards,
Litty Preeth


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jan 30, 2009 7:10 am 
Senior
Senior

Joined: Thu Jan 08, 2009 3:48 pm
Posts: 168
- Naming the ID "id" is usually the better choice, especially when you have another property with the same name
- setting the type to RouterBO is wrong, you should take a value type like long or int
Did you change the internal variable and set/get methods too when you changed to long? If not that would explain the error


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jan 30, 2009 12:59 pm 
Expert
Expert

Joined: Fri Jan 30, 2009 1:47 am
Posts: 292
Location: Bangalore, India
Quote:
Did you change the internal variable and set/get methods too when you changed to long? If not that would explain the error

No I cant change the type of internal variable coz that column is a foreign key also. Its like routerId is the primary key of the view and it references the ROUTER table also. So when I do a getRouterId() I want to get the corresponding routerbo object.

So I think the other option is better.

Anyways thanks for ur support.

- Litty Preeth


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