-->
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: trouble to setup hibernate for the first time
PostPosted: Thu Aug 07, 2008 3:31 pm 
Newbie

Joined: Thu Aug 07, 2008 2:39 pm
Posts: 1
Hi,

I am currently tring to work with Hibernate for the first time, but I alywase get the following exception:

Code:
com.google.gwt.user.server.rpc.UnexpectedException: Service method 'public abstract void org.ERPPrototyp.client.RPC.LoginService.login(java.lang.String,java.lang.String) throws org.ERPPrototyp.client.exceptions.AuthenticationException' threw an unexpected exception: org.hibernate.HibernateException: identifier of an instance of org.ERPPrototyp.User was altered from 1 to 1
        at com.google.gwt.user.server.rpc.RPC.encodeResponseForFailure(RPC.java:360)
        at com.google.gwt.user.server.rpc.RPC.invokeAndEncodeResponse(RPC.java:546)
        at com.google.gwt.user.server.rpc.RemoteServiceServlet.processCall(RemoteServiceServlet.java:163)
        at com.google.gwt.user.server.rpc.RemoteServiceServlet.doPost(RemoteServiceServlet.java:85)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:710)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
        at org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:390)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
        at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
        at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
[...and so on]


I have realy no Idea what this could mean. This is my code:


Code:
public class User {

    private Integer userId;
    private String firstName = "";
   
    //Getter and setter
}

public class UserTest {
    public User buildUser() {
        User user = new User();
        user.setFirstName("John");
        return user;
    }
   
    public void startTest() {  //entry Point
        User user = buildUser();
        SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory();
        Session session = sessionFactory.openSession();
       
        session.save(user);
        session.flush();
    }


And finaly my config:


Code:
User.hbm.xml:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
    <!-- <class dynamic-insert="false" dynamic-update="false" mutable="true" name="org.ERPPrototyp.User" optimistic-lock="version" polymorphism="implicit" select-before-update="false" table="users"> -->

    <class name="org.ERPPrototyp.User" table="users">
        <id name="userId" type="java.lang.Integer" column="user_id" >
            <generator class="increment" />
        </id>
        <property name="firstName" type="java.lang.String" column="first_name" length="20" />
    </class>
</hibernate-mapping>



hibernate.cfg.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
  <session-factory name="session1">
    <property name="hibernate.connection.driver_class">org.postgresql.Driver</property>
    <property name="hibernate.connection.url">jdbc:postgresql://localhost:5432/erp</property>
    <property name="hibernate.connection.username">uname</property>
    <property name="hibernate.connection.password">pw</property>
    <property name="hibernate.show_sql">true</property>
    <property name="dialect">org.hibernate.dialect.PostgreSQLDialect</property>
    <!-- Currently I have no Idea what autocommit does, but it sounds freakin awsome -->
    <property name="connection.autocommit">true</property>
    <!-- Mapping files -->
    <!-- <mapping resource="com/visualbuilder/hibernate/User.hbm.xml" /> -->
    <mapping resource="User.hbm.xml"/>
    <!-- <mapping resource="hibernate.hbm.xml"/> -->
  </session-factory>
</hibernate-configuration>



CREATE TABLE users
(
  user_id integer NOT NULL,
  first_name character varying(20),
  CONSTRAINT users_pkey PRIMARY KEY (user_id)
)
WITH (OIDS=FALSE);
ALTER TABLE users OWNER TO erp;




I know, this is lots of code, that I am posting, but I hope I didn't forgott anything.


Thanks.

Cu,
iuiz


//edit
Code:
got this from my tomcat log:
Hibernate: select max(user_id) from users
Hibernate: insert into users (first_name, user_id) values (?, ?)


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 07, 2008 10:33 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
Wrap you code with a try/catch and transaction demarcation (many samples in the docs). Obviously, auto commit would not be appropriate - I suggest you forget about auto commit. Have fun.


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.