Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp
Using hibernate 3-1
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="com.hibernatebook.chap3.StockInfo" table="StockInfo" >
<id name="stockID" column="stockID" type="java.lang.Long" unsaved-value="0">
<generator class="identity"/>
</id>
<property name="name" column="name" type="java.lang.String" />
<property name="shareCount" column="shareCount" type="java.lang.String" />
<property name="sharePPU" column="sharePPU" type="java.lang.String" />
<property name="buyRate" column="buyRate" type="java.lang.String" />
<property name="sellRate" column="sellRate" type="java.lang.String" />
</class>
</hibernate-mapping>
I am using posgtres 8.1
I am going though a java / hibernate book, that was written against MySQL. I have made some minor changes to the hibernate.properties files to point to the postgres drive. But I am running into some strange results.
using the mapping file above, the test application accepts input and saves it as a persistant object
Code:
session.save(stockInfo);
session.flush();
so all the info is saved from the input form and then the object is saved. but it is not in the Database, I use psql to check the db and there are no records. The primary key seq has risen, but the data wasn't stored. Now the really strange thing is that when I do a search on this table for the newly stored data, I get returned the original data.
I have found if I turn on auto commit in the hibernate.properties it saves it. In fact if I go furthor into the application and do an update it uses begintransaction and commit - which saves it into the DB. This phantom data is only available whilst the application is running
Code:
08:37:30,266 DEBUG QueryTranslatorImpl:236 - parse() - HQL: select stockinfo from com.hibernatebook.chap3.StockInfo stockinfo where stockinfo.name = 'test'
08:37:30,275 DEBUG AST:252 - --- HQL AST ---
\-[QUERY] 'query'
+-[SELECT_FROM] 'SELECT_FROM'
| +-[FROM] 'from'
| | \-[RANGE] 'RANGE'
| | +-[DOT] '.'
| | | +-[DOT] '.'
| | | | +-[DOT] '.'
| | | | | +-[IDENT] 'com'
| | | | | \-[IDENT] 'hibernatebook'
| | | | \-[IDENT] 'chap3'
| | | \-[IDENT] 'StockInfo'
| | \-[ALIAS] 'stockinfo'
| \-[SELECT] 'select'
| \-[IDENT] 'stockinfo'
\-[WHERE] 'where'
\-[EQ] '='
+-[DOT] '.'
| +-[IDENT] 'stockinfo'
| \-[IDENT] 'name'
\-[QUOTED_STRING] ''test''
08:37:30,277 DEBUG ErrorCounter:68 - throwQueryException() : no errors
08:37:30,278 DEBUG HqlSqlBaseWalker:111 - select << begin [level=1, statement=select]
08:37:30,280 DEBUG FromElement:104 - FromClause{level=1} : com.hibernatebook.chap3.StockInfo (stockinfo) -> stockinfo0_
08:37:30,282 DEBUG FromReferenceNode:51 - Resolved : stockinfo -> stockinfo0_.stockID
08:37:30,287 DEBUG FromReferenceNode:51 - Resolved : stockinfo -> stockinfo0_.stockID
08:37:30,289 DEBUG DotNode:541 - getDataType() : name -> org.hibernate.type.StringType@3496212a
08:37:30,291 DEBUG FromReferenceNode:51 - Resolved : stockinfo.name -> stockinfo0_.name
08:37:30,295 DEBUG HqlSqlBaseWalker:117 - select : finishing up [level=1, statement=select]
08:37:30,296 DEBUG HqlSqlWalker:511 - processQuery() : ( SELECT ( {select clause} stockinfo0_.stockID ) ( FromClause{level=1} StockInfo stockinfo0_ ) ( where ( = ( stockinfo0_.name stockinfo0_.stockID name ) 'test' ) ) )
08:37:30,298 DEBUG JoinProcessor:128 - Using FROM fragment [StockInfo stockinfo0_]
08:37:30,300 DEBUG HqlSqlBaseWalker:123 - select >> end [level=1, statement=select]
08:37:30,306 DEBUG AST:222 - --- SQL AST ---
\-[SELECT] QueryNode: 'SELECT' querySpaces (StockInfo)
+-[SELECT_CLAUSE] SelectClause: '{select clause}'
| +-[ALIAS_REF] IdentNode: 'stockinfo0_.stockID as stockID0_' {alias=stockinfo, className=com.hibernatebook.chap3.StockInfo, tableAlias=stockinfo0_}
| \-[SQL_TOKEN] SqlFragment: 'stockinfo0_.name as name0_, stockinfo0_.shareCount as shareCount0_, stockinfo0_.sharePPU as sharePPU0_, stockinfo0_.buyRate as buyRate0_, stockinfo0_.sellRate as sellRate0_'
+-[FROM] FromClause: 'from' FromClause{level=1, fromElementCounter=1, fromElements=1, fromElementByClassAlias=[stockinfo], fromElementByTableAlias=[stockinfo0_], fromElementsByPath=[], collectionJoinFromElementsByPath=[], impliedElements=[]}
| \-[FROM_FRAGMENT] FromElement: 'StockInfo stockinfo0_' FromElement{explicit,not a collection join,not a fetch join,fetch non-lazy properties,classAlias=stockinfo,role=null,tableName=StockInfo,tableAlias=stockinfo0_,origin=null,colums={,className=com.hibernatebook.chap3.StockInfo}}
\-[WHERE] SqlNode: 'where'
\-[EQ] BinaryLogicOperatorNode: '='
+-[DOT] DotNode: 'stockinfo0_.name' {propertyName=name,dereferenceType=4,propertyPath=name,path=stockinfo.name,tableAlias=stockinfo0_,className=com.hibernatebook.chap3.StockInfo,classAlias=stockinfo}
| +-[ALIAS_REF] IdentNode: 'stockinfo0_.stockID' {alias=stockinfo, className=com.hibernatebook.chap3.StockInfo, tableAlias=stockinfo0_}
| \-[IDENT] IdentNode: 'name' {originalText=name}
\-[QUOTED_STRING] LiteralNode: ''test''
08:37:30,308 DEBUG ErrorCounter:68 - throwQueryException() : no errors
08:37:30,309 DEBUG QueryTranslatorImpl:206 - HQL: select stockinfo from com.hibernatebook.chap3.StockInfo stockinfo where stockinfo.name = 'test'
08:37:30,311 DEBUG QueryTranslatorImpl:207 - SQL: select stockinfo0_.stockID as stockID0_, stockinfo0_.name as name0_, stockinfo0_.shareCount as shareCount0_, stockinfo0_.sharePPU as sharePPU0_, stockinfo0_.buyRate as buyRate0_, stockinfo0_.sellRate as sellRate0_ from StockInfo stockinfo0_ where stockinfo0_.name='test'
08:37:30,312 DEBUG ErrorCounter:68 - throwQueryException() : no errors
08:37:30,314 DEBUG SQL:346 - select stockinfo0_.stockID as stockID0_, stockinfo0_.name as name0_, stockinfo0_.shareCount as shareCount0_, stockinfo0_.sharePPU as sharePPU0_, stockinfo0_.buyRate as buyRate0_, stockinfo0_.sellRate as sellRate0_ from StockInfo stockinfo0_ where stockinfo0_.name='test'
08:37:30,334 DEBUG SQL:346 - insert into StockInfo (name, shareCount, sharePPU, buyRate, sellRate) values (?, ?, ?, ?, ?)
08:37:30,339 DEBUG SQL:346 - select currval('StockInfo_stockID_seq')
I am presuming this is not what is supposed to happen and I am doing something wrong. Because the manual states to not use autocommit=true!
Help
Alex
[/code]