-->
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: help - object not written in to database
PostPosted: Wed Sep 24, 2003 11:45 am 
Beginner
Beginner

Joined: Wed Sep 24, 2003 11:16 am
Posts: 20
Location: Turkey
hi people,
i need help using hibernate. it's rather a newbie question. i'm using postgresql 7.3.2 on linux with jdk1.4.2 and org.postgresql.Driver class. i'm trying to insert a simple object with no associations, one assigned pk of type Long. although i see correct insert sql stmt in hibernate logs, no real rows are written into the db.

my persistent object:

Code:
public class Location {
    private Long fId;
    private int fParent;
    private String fName;

    public Location() {
    }

    /**
     * @hibernate.property
     */
    public int getParent() {
        return fParent;
    }

    public void setParent(int pParent) {
        this.fParent = pParent;
    }

    /**
     * @hibernate.id  column="location_id"
     *  unsaved-value="null"
     *  generator-class="native"
     */
    public Long getId() {
        return fId;
    }

    public void setId(Long id) {
        this.fId = id;
    }

    /**
     * @hibernate.property
     */
    public String getName() {
        return fName;
    }

    public void setName(String name) {
        this.fName = name;
    }
}

my mapping file:

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

<hibernate-mapping>
    <class
        name="domain.transmission.hardware.Location"
        table="location"
    >

        <id
            name="id"
            column="location_id"
            type="java.lang.Long"
            unsaved-value="null"
        >
            <generator class="native">
            </generator>
        </id>

        <property
            name="parent"
            type="int"
            column="parent"
        />

        <property
            name="name"
            type="java.lang.String"
            column="name"
        />

        <!--
            To add non XDoclet property mappings, create a file named
                hibernate-properties-Location.xml
            containing the additional properties and place it in your merge dir.
        -->

    </class>

</hibernate-mapping>


my test code:

Code:
       try {
            Configuration cfg = new Configuration().addClass(Location.class);
            SessionFactory sf = cfg.buildSessionFactory();

//            new SchemaExport(cfg).create(true, true);

            Session sess = sf.openSession();

            Location l = new Location();
            l.setId(new Long(1));
            l.setParent(0);
            l.setName("Izmir");

            Serializable serializable = sess.save(l);
            System.out.println("serializable = " + serializable);
//            l=new Location();
//            sess.load(l,new Integer(1));
//            System.out.println("l.getName() = " + l.getName());
            sess.flush();
            sess.close();
        } catch (HibernateException e) {
            e.printStackTrace();  //To change body of catch statement use Options | File Templates.
        }


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 24, 2003 11:48 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Commit the transaction.

Please read the Hibernate FAQ.


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.