-->
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: stackoverflow while updating entity
PostPosted: Fri Jun 11, 2010 2:26 pm 
Newbie

Joined: Fri Jun 11, 2010 1:57 pm
Posts: 2
Hello,
I am a newbie trying to use Hibernate and JPA for developing my graduating thesis.
I have a DocumentFolder entity that I want to update, but when I try to do it I receive a stackoverflow exception. the entities involved are as below:

Code:
@Entity
@Table(name = "Document_Folder")
public class DocumentFolder
{
    @ManyToOne
    private UserAccount moderator;
   
    @OneToMany(mappedBy="pk.documentFolder", cascade = {CascadeType.ALL}/*, fetch = FetchType.EAGER*/)
    private List<ParamDocumentFolder> paramDocumentFolder ;

   //getters and setters here
}

@Entity
public class ParamDocumentFolder
{
    @EmbeddedId
    ParamDocumentFolderPK pk = new ParamDocumentFolderPK();
   
    @Column(name = "Value")
    private String value;
   
   
   
    @Transient
    public DocumentFolder getDocumentFolder()
    {
        return pk.getDocumentFolder();
    }

    public void setDocumentFolder(DocumentFolder documentFolder)
    {
        pk.setDocumentFolder(documentFolder);
    }

    @Transient
    public Params getParam()
    {
        return pk.getParam();
    }

    public void setParam(Params param)
    {
        pk.setParam(param);
    }

//getters and setters here

}


@Embeddable
public class ParamDocumentFolderPK implements Serializable
{
    @ManyToOne
    @JoinColumn(name="idDocumentFolder")
    private DocumentFolder documentFolder;
   
    @ManyToOne()
    @JoinColumn(name="idParam")
    private Params param;


    @Override
    public int hashCode()
    {
        final int prime = 31;
        int result = 1;
        result = prime * result
                + ((documentFolder == null) ? 0 : documentFolder.hashCode());
        result = prime * result + ((param == null) ? 0 : param.hashCode());
        return result;
    }

    @Override
    public boolean equals(Object obj)
    {
        if (this == obj)
            return true;
        if (obj == null)
            return false;
        if (getClass() != obj.getClass())
            return false;
        ParamDocumentFolderPK other = (ParamDocumentFolderPK) obj;
        if (documentFolder == null)
        {
            if (other.documentFolder != null)
                return false;
        }
        else if (!documentFolder.equals(other.documentFolder))
            return false;
        if (param == null)
        {
            if (other.param != null)
                return false;
        }
        else if (!param.equals(other.param))
            return false;
        return true;
    }

   
    //getters and setters
   
}

I have been able to insert documentFolder entities and also to retrieve a document folder entity from the database using a query like this:
Code:
this.em.createQuery("select folder from DocumentFolder folder left join fetch folder.paramDocumentFolder where id = :id").setParameter("id", id).getSingleResult();


But, when I try to update an entity, using a code like:
Code:
this.em.merge(documentFolder);

I get a stack overflow exception. Can you help me find the problem?
I am using hibernate as JPA implementation inside JBOSS 5.1.0.
The stack trace from JBOSS is:
Code:
2010-06-11 20:41:41,020 INFO  [STDOUT] (http-127.0.0.1-8080-3) Hibernate: select documentfo0_.id as id132_1_, documentfo0_.moderator_id as moderator3_132_1_, documentfo0_.Name as Name132_1_, paramdocum1_.idDocumentFolder as idDocume3_3_, paramdocum1_.idParam as idParam3_, paramdocum1_.idDocumentFolder as idDocume3_141_0_, paramdocum1_.idParam as idParam141_0_, paramdocum1_.Value as Value141_0_ from Document_Folder documentfo0_ left outer join ParamDocumentFolder paramdocum1_ on documentfo0_.id=paramdocum1_.idDocumentFolder where documentfo0_.id=?
2010-06-11 20:41:41,528 ERROR [org.jboss.aspects.tx.TxPolicy] (http-127.0.0.1-8080-3) javax.ejb.EJBTransactionRolledbackException: Unexpected Error
java.lang.StackOverflowError
   at sun.nio.cs.MS1252$Decoder.<init>(MS1252.java:72)
   at sun.nio.cs.MS1252.newDecoder(MS1252.java:39)
   at java.nio.charset.CharsetEncoder.isLegalReplacement(CharsetEncoder.java:311)
   at java.nio.charset.CharsetEncoder.replaceWith(CharsetEncoder.java:267)
   at java.nio.charset.CharsetEncoder.<init>(CharsetEncoder.java:186)
   at java.nio.charset.CharsetEncoder.<init>(CharsetEncoder.java:209)
   at sun.nio.cs.SingleByteEncoder.<init>(SingleByteEncoder.java:39)
   at sun.nio.cs.MS1252$Encoder.<init>(MS1252.java:115)
   at sun.nio.cs.MS1252.newEncoder(MS1252.java:43)
   at java.lang.StringCoding$StringEncoder.<init>(StringCoding.java:215)
   at java.lang.StringCoding$StringEncoder.<init>(StringCoding.java:207)
   at java.lang.StringCoding.encode(StringCoding.java:266)
   at java.lang.StringCoding.encode(StringCoding.java:284)
   at java.lang.String.getBytes(String.java:986)
   at org.jboss.logging.util.LoggerStream.println(LoggerStream.java:96)
   at org.hibernate.jdbc.util.SQLStatementLogger.logStatement(SQLStatementLogger.java:113)
   at org.hibernate.jdbc.AbstractBatcher.log(AbstractBatcher.java:444)
   at org.hibernate.jdbc.AbstractBatcher.getPreparedStatement(AbstractBatcher.java:511)
   at org.hibernate.jdbc.AbstractBatcher.getPreparedStatement(AbstractBatcher.java:452)
   at org.hibernate.jdbc.AbstractBatcher.prepareQueryStatement(AbstractBatcher.java:161)
   at org.hibernate.loader.Loader.prepareQueryStatement(Loader.java:1573)
   at org.hibernate.loader.Loader.doQuery(Loader.java:696)
   at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:259)
   at org.hibernate.loader.Loader.loadEntity(Loader.java:1881)
   at org.hibernate.loader.entity.AbstractEntityLoader.load(AbstractEntityLoader.java:71)
   at org.hibernate.loader.entity.AbstractEntityLoader.load(AbstractEntityLoader.java:65)
   at org.hibernate.persister.entity.AbstractEntityPersister.load(AbstractEntityPersister.java:3072)
   at org.hibernate.event.def.DefaultLoadEventListener.loadFromDatasource(DefaultLoadEventListener.java:434)
   at org.hibernate.event.def.DefaultLoadEventListener.doLoad(DefaultLoadEventListener.java:415)
   at org.hibernate.event.def.DefaultLoadEventListener.load(DefaultLoadEventListener.java:165)
   at org.hibernate.event.def.DefaultLoadEventListener.proxyOrLoad(DefaultLoadEventListener.java:223)
   at org.hibernate.event.def.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:126)
   at org.hibernate.impl.SessionImpl.fireLoad(SessionImpl.java:905)
   at org.hibernate.impl.SessionImpl.internalLoad(SessionImpl.java:873)
   at org.hibernate.type.EntityType.resolveIdentifier(EntityType.java:590)
   at org.hibernate.type.EntityType.resolve(EntityType.java:412)
   at org.hibernate.type.ComponentType.resolve(ComponentType.java:607)
   at org.hibernate.type.ComponentType.nullSafeGet(ComponentType.java:298)
   at org.hibernate.loader.Loader.getKeyFromResultSet(Loader.java:1121)
   at org.hibernate.loader.Loader.getRowFromResultSet(Loader.java:588)
   at org.hibernate.loader.Loader.doQuery(Loader.java:724)
   at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:259)
   at org.hibernate.loader.Loader.loadEntity(Loader.java:1881)
   at org.hibernate.loader.entity.AbstractEntityLoader.load(AbstractEntityLoader.java:71)
   at org.hibernate.loader.entity.AbstractEntityLoader.load(AbstractEntityLoader.java:65)
   at org.hibernate.persister.entity.AbstractEntityPersister.load(AbstractEntityPersister.java:3072)
   at org.hibernate.event.def.DefaultLoadEventListener.loadFromDatasource(DefaultLoadEventListener.java:434)
   at org.hibernate.event.def.DefaultLoadEventListener.doLoad(DefaultLoadEventListener.java:415)
   at org.hibernate.event.def.DefaultLoadEventListener.load(DefaultLoadEventListener.java:165)
   at org.hibernate.event.def.DefaultLoadEventListener.proxyOrLoad(DefaultLoadEventListener.java:223)
   at org.hibernate.event.def.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:126)
   at org.hibernate.impl.SessionImpl.fireLoad(SessionImpl.java:905)
   at org.hibernate.impl.SessionImpl.internalLoad(SessionImpl.java:873)
   at org.hibernate.type.EntityType.resolveIdentifier(EntityType.java:590)
   at org.hibernate.type.EntityType.resolve(EntityType.java:412)
   at org.hibernate.type.ComponentType.resolve(ComponentType.java:607)
   at org.hibernate.type.ComponentType.nullSafeGet(ComponentType.java:298)
   at org.hibernate.loader.Loader.getKeyFromResultSet(Loader.java:1121)
   at org.hibernate.loader.Loader.getRowFromResultSet(Loader.java:588)
   at org.hibernate.loader.Loader.doQuery(Loader.java:724)
   at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:259)
   at org.hibernate.loader.Loader.loadEntity(Loader.java:1881)

Thanks.


Top
 Profile  
 
 Post subject: Re: stackoverflow while updating entity
PostPosted: Mon Jun 14, 2010 5:08 pm 
Newbie

Joined: Fri Jun 11, 2010 1:57 pm
Posts: 2
I've found a way of solving the problem(or at least a workaround) at:
http://opensource.atlassian.com/projects/hibernate/browse/HHH-4147

In my case, it meant adding the fetch type Lazy to the primary key field:

Code:
@ManyToOne(fetch=FetchType.LAZY)
@JoinColumn(name="idDocumentFolder")
private DocumentFolder documentFolder;


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.