-->
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 loading a simple object
PostPosted: Mon May 09, 2005 5:06 am 
Beginner
Beginner

Joined: Wed May 05, 2004 3:26 am
Posts: 25
Although its a simple query for some reason it does not work. Might be something Ive missed.

Hibernate version:
3.0.2

Mapping documents:
Code:
<?xml version="1.0"?>

<!DOCTYPE hibernate-mapping PUBLIC
    "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
    "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping>
    <class
        name="gr.forthnet.enosis.oli.pojos.OLIPort"
        table="ports"
        dynamic-update="false"
        dynamic-insert="false"
        select-before-update="false"
    >

        <id
            name="id"
            column="id"
            type="java.lang.Long"
        >
            <generator class="increment">
              <!-- 
                  To add non XDoclet generator parameters, create a file named
                  hibernate-generator-params-OLICompany.xml
                  containing the additional parameters and place it in your merge dir.
              -->
            </generator>
            </id>

            <property
            name="code"
            type="java.lang.String"
            update="true"
            insert="true"
            column="code"
        />
        <!--
            To add non XDoclet property mappings, create a file named
                hibernate-properties-OLIPort.xml
            containing the additional properties and place it in your merge dir.
        -->

    </class>

</hibernate-mapping>


Code between sessionFactory.openSession() and session.close():
Code:
session.load(OLIPort.class, new Integer(1));


Name and version of the database you are using:
PostgreSQL 7.4.1

The generated SQL (show_sql=true):
Code:
DEBUG [main] (AbstractBatcher.java:311) - select oliport0_.id as id0_, oliport0_.code as code2_0_ from ports oliport0_ where oliport0_.id=?
Hibernate: select oliport0_.id as id0_, oliport0_.code as code2_0_ from ports oliport0_ where oliport0_.id=?


Debug level Hibernate log excerpt:
Code:
DEBUG [main] (SessionImpl.java:237) - opened session at timestamp: 4569617595674624
DEBUG [main] (DefaultLoadEventListener.java:185) - loading entity: [gr.forthnet.enosis.oli.pojos.OLIPort#1]
DEBUG [main] (DefaultLoadEventListener.java:258) - creating new proxy for entity
DEBUG [main] (SessionImpl.java:589) - initializing proxy: [gr.forthnet.enosis.oli.pojos.OLIPort#1]
DEBUG [main] (DefaultLoadEventListener.java:331) - attempting to resolve: [gr.forthnet.enosis.oli.pojos.OLIPort#1]
DEBUG [main] (DefaultLoadEventListener.java:367) - object not resolved in any cache: [gr.forthnet.enosis.oli.pojos.OLIPort#1]
DEBUG [main] (BasicEntityPersister.java:2457) - Materializing entity: [gr.forthnet.enosis.oli.pojos.OLIPort#1]
DEBUG [main] (Loader.java:1302) - loading entity: [gr.forthnet.enosis.oli.pojos.OLIPort#1]
DEBUG [main] (AbstractBatcher.java:277) - about to open PreparedStatement (open PreparedStatements: 0, globally: 0)
DEBUG [main] (AbstractBatcher.java:422) - opening JDBC connection
DEBUG [main] (AbstractBatcher.java:311) - select oliport0_.id as id0_, oliport0_.code as code2_0_ from ports oliport0_ where oliport0_.id=?
Hibernate: select oliport0_.id as id0_, oliport0_.code as code2_0_ from ports oliport0_ where oliport0_.id=?
DEBUG [main] (AbstractBatcher.java:365) - preparing statement
DEBUG [main] (NullableType.java:59) - binding '1' to parameter: 1

_________________
The Bits Control The Atoms


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 09, 2005 5:45 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
what do you mean by not working

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 09, 2005 5:55 am 
Beginner
Beginner

Joined: Wed May 05, 2004 3:26 am
Posts: 25
You are right...

I mean that I do get an OLIPort object but neither the "code" or "id" values are set.

_________________
The Bits Control The Atoms


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 09, 2005 6:13 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
either getter/setter issue or maybe your equals/hashCode implem

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 09, 2005 6:18 am 
Beginner
Beginner

Joined: Wed May 05, 2004 3:26 am
Posts: 25
emmanuel, first of all thanks for your prompt replies.

I though I need to implement eq/hash when using a composite key :/

Here is the impl of the class
Code:
public class OLIPort implements Persistent
{
    protected Long id;
    protected String code;

    /**
     *
     */
    public OLIPort()
    {
        this.id = null;
        this.code = "";
    }
   
    public OLIPort(String code)
    {
        this();
        this.code = code;
    }

    /**
     * @hibernate.id
     *  generator-class = "increment"
     */
    public Long getId() {
    return id;
    }
   
    public void setId(Long id) {
        this.id = id;
    }
   
    /**
     * @hibernate.property
     */
    public String getCode() {
    return code;
    }
   
    public void setCode(String code) {
        this.code = code;
    }
   
    public Object exists()
    {
        HiberRequest request = new HiberRequest(OLIDatabaseQueries.PORT);
        request.addParam("code", getCode());
        List result = new HiberClient(HiberDatabase.getInstance()).list(request);
       
        if(result == null || result.isEmpty())
            return null;
        else       
            return result.get(0);
    }
}

_________________
The Bits Control The Atoms


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.