-->
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.  [ 7 posts ] 
Author Message
 Post subject: could not fetch initial value for increment generator
PostPosted: Sun Apr 29, 2007 10:37 pm 
Newbie

Joined: Wed Jan 24, 2007 12:14 am
Posts: 2
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version:3.1

Mapping documents:
<?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">
<!--
Mapping file autogenerated by MyEclipse - Hibernate Tools
-->
<hibernate-mapping>
<class name="com.yxcat.opac.pojo.UserTab" table="UserTab" schema="dbo" catalog="YxLibraryDB">
<id name="id" type="java.lang.Integer">
<column name="ID" />
<generator class="increment" />
</id>
<property name="stationId" type="java.lang.Integer">
<column name="StationID" />
</property>
<property name="loginName" type="java.lang.String">
<column name="LoginName" length="20" />
</property>
<property name="libraryId" type="java.lang.Integer">
<column name="LibraryID" />
</property>
<property name="departmentId" type="java.lang.Long">
<column name="DepartmentID" precision="18" scale="0" />
</property>
<property name="loginPsw" type="java.lang.String">
<column name="LoginPsw" length="20" />
</property>
<property name="userCode" type="java.lang.String">
<column name="UserCode" length="50" />
</property>
<property name="userName" type="java.lang.String">
<column name="UserName" length="20" />
</property>
<property name="userSex" type="java.lang.String">
<column name="UserSex" length="10" />
</property>
<property name="userAge" type="java.lang.Integer">
<column name="UserAge" />
</property>
<property name="userIndex" type="java.lang.Integer">
<column name="UserIndex" />
</property>
<property name="userStation" type="java.lang.String">
<column name="UserStation" length="100" />
</property>
<property name="userTel" type="java.lang.String">
<column name="UserTel" length="20" />
</property>
<property name="userFax" type="java.lang.String">
<column name="UserFax" length="20" />
</property>
<property name="userMobile" type="java.lang.String">
<column name="UserMobile" length="20" />
</property>
<property name="userMsn" type="java.lang.String">
<column name="UserMsn" length="100" />
</property>
<property name="userQq" type="java.lang.String">
<column name="UserQQ" length="100" />
</property>
<property name="userAddr" type="java.lang.String">
<column name="UserAddr" length="200" />
</property>
<property name="userPost" type="java.lang.String">
<column name="UserPost" length="10" />
</property>
<property name="loginState" type="java.lang.Integer">
<column name="LoginState" />
</property>
<property name="userTab" type="java.lang.Integer">
<column name="UserTab" />
</property>
<property name="userMemo" type="java.lang.String">
<column name="UserMemo" length="500" />
</property>
<property name="extInt" type="java.lang.Integer">
<column name="ExtInt" />
</property>
<property name="extStr" type="java.lang.String">
<column name="ExtStr" length="200" />
</property>
<property name="extField" type="java.lang.String">
<column name="ExtField" length="500" />
</property>
</class>
</hibernate-mapping>



Code between sessionFactory.openSession() and session.close():

public boolean add(Object object) throws HibernateException {

boolean isAdd = false;

Session session = null;
Transaction ts = null;

try {
session = HibernateSessionFactory.getSession();
ts = session.beginTransaction();

ObjectDAO objectDAO = (ObjectDAO) ObjectDAOFactory
.getInstance()
.getObjectDAO();

if (objectDAO.add(session, object)) { //The code of "objectDAO.add(session, object)" in the end of the function ,look for function"public boolean add(Session session, Object object)
"
ts.commit();
isAdd = true;
}

} catch(Exception e) {
if (ts != null)
ts.rollback();
} finally {
session.close();
}

return isAdd;
}


public boolean add(Session session, Object object)
throws HibernateException {

boolean isAdd = false;

try {

session.save(object);
isAdd = true;

} catch(Exception e) {
e.printStackTrace();
}

return isAdd;
}


Full stack trace of any exception that occurs:

log4j:WARN No appenders could be found for logger (org.hibernate.cfg.Environment).
log4j:WARN Please initialize the log4j system properly.
Hibernate: select max(ID) from UserTab
org.hibernate.exception.SQLGrammarException: could not fetch initial value for increment generator
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:67)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.id.IncrementGenerator.getNext(IncrementGenerator.java:107)
at org.hibernate.id.IncrementGenerator.generate(IncrementGenerator.java:44)
at org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:91)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener.java:186)
at org.hibernate.event.def.DefaultSaveEventListener.saveWithGeneratedOrRequestedId(DefaultSaveEventListener.java:33)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.entityIsTransient(DefaultSaveOrUpdateEventListener.java:175)
at org.hibernate.event.def.DefaultSaveEventListener.performSaveOrUpdate(DefaultSaveEventListener.java:27)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:70)
at org.hibernate.impl.SessionImpl.fireSave(SessionImpl.java:530)
at org.hibernate.impl.SessionImpl.save(SessionImpl.java:518)
at org.hibernate.impl.SessionImpl.save(SessionImpl.java:514)
at com.yxcat.opac.dao.impl.ObjectDAOImpl.add(ObjectDAOImpl.java:123)
at com.yxcat.opac.service.impl.ObjectServiceImpl.add(ObjectServiceImpl.java:219)
at com.yxcat.opac.util.MainTest.saveUser(MainTest.java:27)
at com.yxcat.opac.util.MainTest.main(MainTest.java:13)
Caused by: java.sql.SQLException: [Microsoft][SQLServer 2000 Driver for JDBC][SQLServer]对象名 'UserTab' 无效。
at com.microsoft.jdbc.base.BaseExceptions.createException(Unknown Source)
at com.microsoft.jdbc.base.BaseExceptions.getException(Unknown Source)
at com.microsoft.jdbc.sqlserver.tds.TDSRequest.processErrorToken(Unknown Source)
at com.microsoft.jdbc.sqlserver.tds.TDSRequest.processReplyToken(Unknown Source)
at com.microsoft.jdbc.sqlserver.tds.TDSExecuteRequest.processReplyToken(Unknown Source)
at com.microsoft.jdbc.sqlserver.tds.TDSRequest.processReply(Unknown Source)
at com.microsoft.jdbc.sqlserver.SQLServerImplStatement.getNextResultType(Unknown Source)
at com.microsoft.jdbc.base.BaseStatement.commonTransitionToState(Unknown Source)
at com.microsoft.jdbc.base.BaseStatement.postImplExecute(Unknown Source)
at com.microsoft.jdbc.base.BasePreparedStatement.postImplExecute(Unknown Source)
at com.microsoft.jdbc.base.BaseStatement.commonExecute(Unknown Source)
at com.microsoft.jdbc.base.BaseStatement.executeQueryInternal(Unknown Source)
at com.microsoft.jdbc.base.BasePreparedStatement.executeQuery(Unknown Source)
at org.hibernate.id.IncrementGenerator.getNext(IncrementGenerator.java:85)
... 14 more



Name and version of the database you are using:MS SQL Server

The generated SQL (show_sql=true):

Hibernate: select max(ID) from UserTab




desctrition:

I'm not understand why could not fetch initial value for increment generator, I know that the increment id strategy is apply to any database.

there are another problem that i meet , when i update on record of the UserTab ,the hibernate report "Could not read mappings from resource: com/yxcat/opac/pojo/UserTab.hbm.xml", but i can alse update the record successful, why?


Debug level Hibernate log excerpt:


Problems with Session and transaction handling?

Read this: http://hibernate.org/42.html


Top
 Profile  
 
 Post subject:
PostPosted: Mon Apr 30, 2007 4:36 am 
Senior
Senior

Joined: Sat Apr 21, 2007 11:01 pm
Posts: 144
Is your UserTab table empty?

_________________
Everytime you get an answer to your question without giving credit; god kills a kitten. :(


Top
 Profile  
 
 Post subject: help me, thanks
PostPosted: Mon May 07, 2007 8:58 pm 
Newbie

Joined: Wed Jan 24, 2007 12:14 am
Posts: 2
adamgibbons wrote:
Is your UserTab table empty?

No, the UserTab table is not empty.


Top
 Profile  
 
 Post subject: Re: could not fetch initial value for increment generator
PostPosted: Mon Mar 01, 2010 5:06 pm 
Newbie

Joined: Mon Mar 01, 2010 5:04 pm
Posts: 3
Location: Turkey
same problem for me.. need help..


Top
 Profile  
 
 Post subject: Re: could not fetch initial value for increment generator
PostPosted: Mon Mar 01, 2010 5:44 pm 
Senior
Senior

Joined: Wed Sep 19, 2007 9:31 pm
Posts: 191
Location: Khuntien (Indonesia)
talha06 wrote:
same problem for me.. need help..

please post your hibernate configuration?
what library do you use?


Top
 Profile  
 
 Post subject: Re: could not fetch initial value for increment generator
PostPosted: Mon Mar 01, 2010 5:56 pm 
Newbie

Joined: Mon Mar 01, 2010 5:04 pm
Posts: 3
Location: Turkey
SIau_Tie wrote:
talha06 wrote:
same problem for me.. need help..

please post your hibernate configuration?
what library do you use?

thank you for your interest. Here's my configuration code :
Code:
<?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>
        <property name="hibernate.connection.driver_class">oracle.jdbc.driver.OracleDriver</property>
        <property name="hibernate.connection.password">00</property>
        <property name="hibernate.connection.url">jdbc:oracle:thin:@localhost:1521:xe</property>
        <property name="hibernate.connection.username">talha</property>
        <property name="hibernate.default_catalog">TALHA</property>
        <property name="hibernate.default_schema">TALHA</property>
        <property name="hibernate.dialect">org.hibernate.dialect.Oracle10gDialect</property>
        <property name="show_sql">true</property>
        <mapping resource="model/Kisi.hbm.xml"/>         
    </session-factory>
</hibernate-configuration>

I'm using many libraries including Hibernate-Core-3.5-0, commons-logging, persistence, etc.


Top
 Profile  
 
 Post subject: Re: could not fetch initial value for increment generator
PostPosted: Tue Mar 02, 2010 1:42 am 
Senior
Senior

Joined: Wed Sep 19, 2007 9:31 pm
Posts: 191
Location: Khuntien (Indonesia)
Just now, I tested with Hibernate 3.5.0 CR 2 and oracle 10g. it works fine


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