-->
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.  [ 6 posts ] 
Author Message
 Post subject: many-to-one for a foreign key generates strange error
PostPosted: Mon Mar 07, 2011 9:59 am 
Newbie

Joined: Wed Mar 02, 2011 9:50 am
Posts: 15
Trying to add a foreign key constraint de my class (working well at the moment):

Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
        "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
        "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">

<hibernate-mapping package="com.andromas.bgp.web.core.model.gwtplategridrequest">

   <class name="WellInfo" table="WELLS">

      <id name="id" type="long" column="ID">
         <generator class="native" />
      </id>
      <!-- <composite-id name="id" class="com.andromas.bgp.web.core.model.gwtplategridresponse.WellInfoIdType">
         <key-many-to-one name="plateId" class="com.andromas.bgp.web.core.model.gwtopenplaterequest.PlateType"></key-many-to-one>
         <key-property name="name" column="NAME" type="string" /> </composite-id> -->
      <property name="name" type="string" column="NAME" not-null="true"></property>
      <property name="barcode" type="string" column="BARCODE"
         not-null="true"></property>
      <property name="method" type="string" column="METHOD"
         not-null="true"></property>

      <property name="needAcquisition" type="boolean" column="NEED_ACQUISITION"></property>
      <property name="identificationResult" type="string" column="RESULT"></property>

      <property name="plateId" type="long" column="PLATE_ID" not-null="true"></property>

   </class>
</hibernate-mapping>



as soon as i change:
Code:
<property name="plateId" type="long" column="PLATE_ID" not-null="true"></property>

for
Code:
   <many-to-one name="plateId"
         class="com.andromas.bgp.web.core.model.gwtnewplaterequest.PlateType"
         column="PLATE_ID"></many-to-one>



i get the following error as soon as i add the <many-to-one> tag:

Code:
org.hibernate.PropertyAccessException: IllegalArgumentException occurred calling getter of com.andromas.bgp.web.core.model.gwtnewpla
terequest.PlateType.id
        at org.hibernate.property.BasicPropertyAccessor$BasicGetter.get(BasicPropertyAccessor.java:198)
        at org.hibernate.tuple.entity.AbstractEntityTuplizer.getIdentifier(AbstractEntityTuplizer.java:230)
        at org.hibernate.persister.entity.AbstractEntityPersister.getIdentifier(AbstractEntityPersister.java:3852)
        at org.hibernate.persister.entity.AbstractEntityPersister.isTransient(AbstractEntityPersister.java:3560)
        at org.hibernate.engine.ForeignKeys.isTransient(ForeignKeys.java:204)
        at org.hibernate.engine.ForeignKeys$Nullifier.isNullifiable(ForeignKeys.java:160)
        at org.hibernate.engine.ForeignKeys$Nullifier.nullifyTransientReferences(ForeignKeys.java:92)
        at org.hibernate.engine.ForeignKeys$Nullifier.nullifyTransientReferences(ForeignKeys.java:70)
        at org.hibernate.event.def.AbstractSaveEventListener.performSaveOrReplicate(AbstractSaveEventListener.java:311)
        at org.hibernate.event.def.AbstractSaveEventListener.performSave(AbstractSaveEventListener.java:204)
        at org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:130)
        at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener.
java:210)
        at org.hibernate.event.def.DefaultSaveEventListener.saveWithGeneratedOrRequestedId(DefaultSaveEventListener.java:56)
        at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.entityIsTransient(DefaultSaveOrUpdateEventListener.java:195)
        at org.hibernate.event.def.DefaultSaveEventListener.performSaveOrUpdate(DefaultSaveEventListener.java:50)
        at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:93)
        at org.hibernate.impl.SessionImpl.fireSave(SessionImpl.java:705)
        at org.hibernate.impl.SessionImpl.save(SessionImpl.java:693)
        at org.hibernate.impl.SessionImpl.save(SessionImpl.java:689)
        at com.andromas.bgp.servlet.RESTHandler.updateWellRecord(RESTHandler.java:296)
        at com.andromas.bgp.servlet.RESTHandler.doPost(RESTHandler.java:229)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
        at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:487)
        at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1093)
        at org.springframework.security.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:394)
        at org.springframework.security.intercept.web.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:109)
        at org.springframework.security.intercept.web.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:83)
        at org.springframework.security.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:406)
        at org.springframework.security.ui.SessionFixationProtectionFilter.doFilterHttp(SessionFixationProtectionFilter.java:67)
        at org.springframework.security.ui.SpringSecurityFilter.doFilter(SpringSecurityFilter.java:53)
        at org.springframework.security.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:406)
        at org.springframework.security.ui.ExceptionTranslationFilter.doFilterHttp(ExceptionTranslationFilter.java:101)
        at org.springframework.security.ui.SpringSecurityFilter.doFilter(SpringSecurityFilter.java:53)
        at org.springframework.security.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:406)
        at org.springframework.security.providers.anonymous.AnonymousProcessingFilter.doFilterHttp(AnonymousProcessingFilter.java:10
5)
        at org.springframework.security.ui.SpringSecurityFilter.doFilter(SpringSecurityFilter.java:53)
        at org.springframework.security.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:406)
        at org.springframework.security.ui.rememberme.RememberMeProcessingFilter.doFilterHttp(RememberMeProcessingFilter.java:116)
        at org.springframework.security.ui.SpringSecurityFilter.doFilter(SpringSecurityFilter.java:53)
        at org.springframework.security.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:406)
        at org.springframework.security.wrapper.SecurityContextHolderAwareRequestFilter.doFilterHttp(SecurityContextHolderAwareReque
stFilter.java:91)
        at org.springframework.security.ui.SpringSecurityFilter.doFilter(SpringSecurityFilter.java:53)
        at org.springframework.security.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:406)
        at org.springframework.security.ui.basicauth.BasicProcessingFilter.doFilterHttp(BasicProcessingFilter.java:174)
        at org.springframework.security.ui.SpringSecurityFilter.doFilter(SpringSecurityFilter.java:53)
        at org.springframework.security.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:406)
        at org.springframework.security.ui.webapp.DefaultLoginPageGeneratingFilter.doFilterHttp(DefaultLoginPageGeneratingFilter.jav
a:86)
        at org.springframework.security.ui.SpringSecurityFilter.doFilter(SpringSecurityFilter.java:53)
        at org.springframework.security.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:406)
        at org.springframework.security.ui.AbstractProcessingFilter.doFilterHttp(AbstractProcessingFilter.java:278)
        at org.springframework.security.ui.SpringSecurityFilter.doFilter(SpringSecurityFilter.java:53)
        at org.springframework.security.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:406)
        at org.springframework.security.ui.logout.LogoutFilter.doFilterHttp(LogoutFilter.java:89)
        at org.springframework.security.ui.SpringSecurityFilter.doFilter(SpringSecurityFilter.java:53)
        at org.springframework.security.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:406)
        at org.springframework.security.context.HttpSessionContextIntegrationFilter.doFilterHttp(HttpSessionContextIntegrationFilter
.java:235)
        at org.springframework.security.ui.SpringSecurityFilter.doFilter(SpringSecurityFilter.java:53)
        at org.springframework.security.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:406)
        at org.springframework.security.util.FilterChainProxy.doFilter(FilterChainProxy.java:185)
        at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:237)
        at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:167)
        at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1084)
        at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:360)
        at org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216)
        at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:181)
        at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:726)
        at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:405)
        at org.mortbay.jetty.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:206)
        at org.mortbay.jetty.handler.HandlerCollection.handle(HandlerCollection.java:114)
        at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
        at org.mortbay.jetty.Server.handle(Server.java:324)
        at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:505)
        at org.mortbay.jetty.HttpConnection$RequestHandler.content(HttpConnection.java:843)
        at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:648)
        at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:211)
        at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:380)
        at org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:395)
        at org.mortbay.thread.QueuedThreadPool$PoolThread.run(QueuedThreadPool.java:488)
Caused by: java.lang.IllegalArgumentException: object is not an instance of declaring class
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
        at java.lang.reflect.Method.invoke(Unknown Source)
        at org.hibernate.property.BasicPropertyAccessor$BasicGetter.get(BasicPropertyAccessor.java:172)
        ... 78 more



And here is my PlateType class:
Code:
//
// This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, vhudson-jaxb-ri-2.1-2
// See <a href="http://java.sun.com/xml/jaxb">http://java.sun.com/xml/jaxb</a>
// Any modifications to this file will be lost upon recompilation of the source schema.
// Generated on: 2011.03.07 at 02:40:51 PM CET
//


package com.andromas.bgp.web.core.model.gwtnewplaterequest;

import java.io.Serializable;
import java.util.Calendar;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlSchemaType;
import javax.xml.bind.annotation.XmlType;
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;


/**
* <p>Java class for plateType complex type.
*
* <p>The following schema fragment specifies the expected content contained within this class.
*
* <pre>
* &lt;complexType name="plateType">
*   &lt;complexContent>
*     &lt;restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
*       &lt;sequence>
*         &lt;element name="id" type="{http://www.w3.org/2001/XMLSchema}long"/>
*         &lt;element name="creationDate" type="{http://www.w3.org/2001/XMLSchema}dateTime"/>
*         &lt;element name="modificationDate" type="{http://www.w3.org/2001/XMLSchema}dateTime" minOccurs="0"/>
*         &lt;element name="barcode" type="{http://www.w3.org/2001/XMLSchema}string" minOccurs="0"/>
*         &lt;element name="creator" type="{http://www.w3.org/2001/XMLSchema}string"/>
*         &lt;element name="noBarcode" type="{http://www.w3.org/2001/XMLSchema}boolean" minOccurs="0"/>
*       &lt;/sequence>
*     &lt;/restriction>
*   &lt;/complexContent>
* &lt;/complexType>
* </pre>
*
*
*/
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "plateType", propOrder = {
    "id",
    "creationDate",
    "modificationDate",
    "barcode",
    "creator",
    "noBarcode"
})
public class PlateType
    implements Serializable
{

    private final static long serialVersionUID = 1L;
    protected long id;
    @XmlElement(required = true, type = String.class)
    @XmlJavaTypeAdapter(Adapter1 .class)
    @XmlSchemaType(name = "dateTime")
    protected Calendar creationDate;
    @XmlElement(type = String.class)
    @XmlJavaTypeAdapter(Adapter1 .class)
    @XmlSchemaType(name = "dateTime")
    protected Calendar modificationDate;
    protected String barcode;
    @XmlElement(required = true)
    protected String creator;
    protected Boolean noBarcode;

    /**
     * Gets the value of the id property.
     *
     */
    public long getId() {
        return id;
    }

    /**
     * Sets the value of the id property.
     *
     */
    public void setId(long value) {
        this.id = value;
    }

    /**
     * Gets the value of the creationDate property.
     *
     * @return
     *     possible object is
     *     {@link String }
     *     
     */
    public Calendar getCreationDate() {
        return creationDate;
    }

    /**
     * Sets the value of the creationDate property.
     *
     * @param value
     *     allowed object is
     *     {@link String }
     *     
     */
    public void setCreationDate(Calendar value) {
        this.creationDate = value;
    }

    /**
     * Gets the value of the modificationDate property.
     *
     * @return
     *     possible object is
     *     {@link String }
     *     
     */
    public Calendar getModificationDate() {
        return modificationDate;
    }

    /**
     * Sets the value of the modificationDate property.
     *
     * @param value
     *     allowed object is
     *     {@link String }
     *     
     */
    public void setModificationDate(Calendar value) {
        this.modificationDate = value;
    }

    /**
     * Gets the value of the barcode property.
     *
     * @return
     *     possible object is
     *     {@link String }
     *     
     */
    public String getBarcode() {
        return barcode;
    }

    /**
     * Sets the value of the barcode property.
     *
     * @param value
     *     allowed object is
     *     {@link String }
     *     
     */
    public void setBarcode(String value) {
        this.barcode = value;
    }

    /**
     * Gets the value of the creator property.
     *
     * @return
     *     possible object is
     *     {@link String }
     *     
     */
    public String getCreator() {
        return creator;
    }

    /**
     * Sets the value of the creator property.
     *
     * @param value
     *     allowed object is
     *     {@link String }
     *     
     */
    public void setCreator(String value) {
        this.creator = value;
    }

    /**
     * Gets the value of the noBarcode property.
     *
     * @return
     *     possible object is
     *     {@link Boolean }
     *     
     */
    public Boolean isNoBarcode() {
        return noBarcode;
    }

    /**
     * Sets the value of the noBarcode property.
     *
     * @param value
     *     allowed object is
     *     {@link Boolean }
     *     
     */
    public void setNoBarcode(Boolean value) {
        this.noBarcode = value;
    }

}





Could you please help me ?

Thanks a lot


Top
 Profile  
 
 Post subject: Re: many-to-one for a foreign key generates strange error
PostPosted: Wed Mar 09, 2011 4:43 am 
Newbie

Joined: Wed Mar 02, 2011 9:50 am
Posts: 15
I suppose it is a real newbie problem, i've been using hibernate for 2 weeks only, but everytime i create a many-to-one tag, i have problems saving my object, with cast exceptions.

Anyone could help please ?

Thanks


Top
 Profile  
 
 Post subject: Re: many-to-one for a foreign key generates strange error
PostPosted: Mon Mar 14, 2011 4:10 am 
Newbie

Joined: Wed Mar 02, 2011 9:50 am
Posts: 15
somebody ?
thanks a lot


Top
 Profile  
 
 Post subject: Re: many-to-one for a foreign key generates strange error
PostPosted: Mon Mar 14, 2011 6:05 am 
Expert
Expert

Joined: Wed Mar 03, 2004 6:35 am
Posts: 1240
Location: Lund, Sweden
Quote:
as soon as i change:

Code:
<property name="plateId" type="long" column="PLATE_ID" not-null="true"></property>


for
Code:
   <many-to-one name="plateId"
         class="com.andromas.bgp.web.core.model.gwtnewplaterequest.PlateType"
         column="PLATE_ID"></many-to-one>



You'll also need to make the corresponding change in your code. In your class WellInfo you probably have something like this:

Code:
private long plateId;
public long getPlateId()
{
  return plateId;
}
public void setPlateId(long plateId)
{
   this.plateId = plateId;
}


which need to be changed to:

Code:
private PlateType plateId;
public PlateType getPlateId()
{
  return plateId;
}
public void setPlateId(PlateType plateId)
{
   this.plateId = plateId;
}



I think you should also change naming conventions... eg. methods should be getPlateType()/setPlateType() and in the mapping <many-to-one name="plateType" ....>


Top
 Profile  
 
 Post subject: Re: many-to-one for a foreign key generates strange error
PostPosted: Tue Mar 15, 2011 6:32 am 
Newbie

Joined: Wed Mar 02, 2011 9:50 am
Posts: 15
thanks a lot, i'm going to check this!
:)


Top
 Profile  
 
 Post subject: Re: many-to-one for a foreign key generates strange error
PostPosted: Mon Jun 09, 2014 2:38 am 
Newbie

Joined: Mon Jun 09, 2014 12:13 am
Posts: 1
i am having the same problem. will i solve my problem by changing these codes. i will try. appreciate the help.


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