Hibernate common errors
1. Error: object references an unsaved transient instance - save the transient instance before flushing:

com.xxxx.bean.java.Sysblog; nested exception is org.hibernate.TransientObjectException: object references an unsaved

transient instance - save the transient instance before flushing: com.xxx.bean.java.Sysblog

Solution: there is no predictable examples, of course, we must instantiate objects pyronaridine

2. Error: Exceptionobject references an unsaved transient instance - save the transient instance before flushing:

src.persistent.Product ......

Solution: there is no reason for an object set settings, such as this is above a certain object does not call setProduct

3. Error: Illegal attempt to associate a collection with two open sessions ......

Solution: (hibernate's session provided a cache, each session, the same id twice a load, does not send two sql database, but the session closed

When a cache on a failure.

sysblogarticle.setAmount (new Long (sysblogcommentService.selcom (
sysblogarticle.getArticleid (). toString ()). size ()));// article id through access to a few article comments
sysblogarticle.setSysblogcomments (null); / / key
sysblogarticleService.saveOrUpdate (sysblogarticle); / / article in the comments section will be a few modifications
Reference: http://javaflasher.javaeye.com/blog/forum/17913

4. Error: Hbm mapping documents are generated after a good, change the database to increase the default value (such as: will be a field value is set to 1), inserted at the time the results, the database side there was no response.

Solution: in sql-type inside the definition of the database default values, then SchemeExport time, DDL will add default. HBM then defined as the dynamic-insert = "true" and

dynamic-update = "true"
<hibernate-mapping>
<class name="com.tom.hibernate.EbayItem" table="EBAY_ITEM" schema="API_USER" dynamic-insert="true" dynamic-update="true">
.......
........
<property name="viewData" not-null="true" type="boolean">
<column name="viewdata" sql-type="number(1) default 0"/>
</ property>

</ class>
</ hibernate-mapping>

5. Error:
2008-2-2 9:45:13 org.hibernate.util.JDBCExceptionReporter logExceptions
Serious: Unknown column 'tjsaleresu0_.isupdate' in 'field list'
2008-2-2 9:45:13 org.hibernate.event.def.DefaultLoadEventListener onLoad
Information: Error performing load command
org.hibernate.exception.SQLGrammarException: could not load an entity: [ookj.domain.TjSaleResult # 293]

- The database is not "isupdate" field

6. Error:
2008-2-2 9:51:42 org.hibernate.util.JDBCExceptionReporter logExceptions
Warning: SQL Error: 1052, SQLState: 23000
2008-2-2 9:51:42 org.hibernate.util.JDBCExceptionReporter logExceptions
Serious: Column 'df' in where clause is ambiguous

---- Find ( "select tsr from TjSaleResult tsr, TjItemResult tir where tsr = tir.saleResultId and tir =? And df <> 1", new Object

[] (tir));
---- Statement of df can not determine which table

7. Error
org.springframework.orm.hibernate3.HibernateQueryException: could not resolve property: trackDate of:

ookj.domain.TjReagentTrack [from ookj.domain.TjReagentTrack trt where trt.trackStage =? and trt.trackDate =? and trt.userId =?

and trt.df <> 1]; nested exception is org.hibernate.QueryException: could not resolve property: trackDate of:

ookj.domain.TjReagentTrack [from ookj.domain.TjReagentTrack trt where trt.trackStage =? and trt.trackDate =? and trt.userId =?

and trt.df <> 1]
Caused by: org.hibernate.QueryException: could not resolve property: trackDate of: ookj.domain.TjReagentTrack [from

ookj.domain.TjReagentTrack trt where trt.trackStage =? and trt.trackDate =? and trt.userId =? and trt.df <> 1]

---- Configuration questions are:
private static String [] [] properties = (
( "getReagentTrackId", "reagent_trackid", "0"),
( "getReagentId", "reagentid", "1"),
( "getUserId", "userid", "1"),
( "getGuideBookId", "guidebookid", "1"),
( "getTrackTime", "tracktime", "0"), / / here the name wrong
( "trackStage", "trackstage", "0"),
( "getDf", "df", "0")
---- Have nd trt.trackDate =? Statement the value is incorrect.

8. Error
java.lang.ClassCastException: ookj.domain.OokjDateTime

---- Basic type conversion error

9. Error
org.springframework.dao.InvalidDataAccessApiUsageException: object references an unsaved transient instance - save the

transient instance before flushing: ookj.domain.SmDept; nested exception is org.hibernate.TransientObjectException: object

references an unsaved transient instance - save the transient instance before flushing: ookj.domain.SmDept
Caused by: org.hibernate.TransientObjectException: object references an unsaved transient instance - save the transient

instance before flushing: ookj.domain.SmDept

---- New object a new, unsaved at prior save it into a new new object.

10. Error
Information: could not read column value from result set: activep19_59_; could not deserialize
Exception in thread "main" org.springframework.orm.hibernate3.HibernateSystemException: could not deserialize; nested

exception is org.hibernate.type.SerializationException: could not deserialize
Caused by: org.hibernate.type.SerializationException: could not deserialize

I used the database is mysql, through automatically generated POJO class category, the field has not been designated type, hibernate automatically assigned, if it can not be generated by anti-type sequence of

Will be dished out java.util.ServilizableException

Anomalies arise such as me because I set up a string [] type of field, but in the corresponding. Hbm.xml document I have no explicit definition of its type, hibernate automatically designated

Type, which can not be anti-serialization.

11. Error
Serious: line 1:143: expecting IDENT, found '.'
2008-2-3 0:41:01 org.apache.catalina.core.StandardWrapperValve invoke
Serious: Servlet.service () for servlet tijianServlet threw exception
org.springframework.orm.hibernate3.HibernateQueryException: expecting IDENT, found '.' near line 1, column 143 [select

t.saleItemId.medicalGroup from ookj.domain.TjSaleResult t where t.guideBookId =? and t.saleItemId.medicalGroup.block =? and

t.saleItemId .. medicalGroup.df <> 1]; nested exception is org.hibernate.hql.ast.QuerySyntaxException: expecting IDENT, found '.'

near line 1, column 143 [select t.saleItemId.medicalGroup from ookj.domain.TjSaleResult t where t.guideBookId =? and

t.saleItemId.medicalGroup.block =? and t.saleItemId .. medicalGroup.df <> 1]
Caused by: org.hibernate.hql.ast.QuerySyntaxException: expecting IDENT, found '.' Near line 1, column 143 [select

t.saleItemId.medicalGroup from ookj.domain.TjSaleResult t where t.guideBookId =? and t.saleItemId.medicalGroup.block =? and

t.saleItemId .. medicalGroup.df <> 1]

_____ More than a point

12. Error
java.net.SocketException: java.net.ConnectException: Connection refused: connect

---- Database not started

13. Error
Serious: Servlet.service () for servlet tijianServlet threw exception
java.lang.NoSuchMethodError: ookj.service.SendReagentService.saveTjSendReagent

(Lookj / domain / TjReagent; Lookj / domain / SaleGuideBook;) [Ljava / lang / String;

---- Tomcat \ Java Virtual concentrated code did not keep up, Can not keep pace, restart the virtual machine just fine.

偶嘀error set [posted 2007-03-04 15:19:00]

1. Hibernate many-to-one to do when encountered an error

(1) org.apache.jasper.JasperException: Error creating bean with name 'sf' defined in ServletContext resource [/ WEB -

INF / applicationContext.xml]: Initialization of bean failed; nested exception is org.hibernate.PropertyNotFoundException:

Could not find a getter for person in class com.accp.vo.Course

Since the configuration file <many-to-one name="person" ../> a person in the property name was wrong.

Have for the following reasons:
1) getter () method was wrong, did not follow the rules of Writing JavaBean.
2) *. hmb.xml the property name and POJO's are consistent. NOTE: The property name is more space.

(2). Hibernate many-to-one error:

save the transient instance before flushing

Specific errors in the one-to-many, to many to save time, add one because there is no foreign production, resulting in an error.
Specific solutions:
(1), at one of the HBM file invest = true
(2), the former must be preserved in the many requirements of one's existence

2.spring + struts + hibernate project debug summary
(1) javax.servlet.ServletException: Cannot retrieve mapping for action / companyNews
struts-config.xml is not related to Writing companyNews of action.

(2) myeclipse add a jar package when you open the project properties, select java build path -> libraries -> add external JARs to select the required

jar package, add, it was found, he loaded the bag are the absolute path, and our project needs cvs sharing, can not commit to the cvs server. myeclipse has prompted the following information:
2 build path entries are missing.

Solution is turn off myeclipse, use notepad to open the project directory. Classpath, manually modified relative path and to check that the specified relative path in the real Tim

Add the jar package, start myeclipse can upload new packages added to the jar.

(3) in the use of junit / StrutsTest time error:
java.lang.UnsupportedClassVersionError: junit / framework / TestListener (Unsupported major.minor version 49.0)

The reason is that if it is jdk1.4, then, can only use the following junit3.8 version, if yes, then use jdk1.5, you must use junit4.0 above.

(4) Cannot find ActionMappings or ActionformBeans collection
The reason is: web.xml file does not configure the struts-config.xml of the relevant information.

(5) org.apache.jasper.JasperException: The absolute uri: http://java.sun.com/jstl/core cannot be resolved in either web.xml

or the jar files deployed with this application

Lack of correlation JSTL jar and web.xml configuration
jstl.jar
<taglib>
<taglib-uri> http://java.sun.com/jstl/fmt </ taglib-uri>
<taglib-location> / WEB-INF/fmt.tld </ taglib-location>
</ taglib>

<taglib>
<taglib-uri> http://java.sun.com/jstl/fmt-rt </ taglib-uri>
<taglib-location> / WEB-INF/fmt-rt.tld </ taglib-location>
</ taglib>

<taglib>
<taglib-uri> http://java.sun.com/jstl/core </ taglib-uri>
<taglib-location> / WEB-INF/c.tld </ taglib-location>
</ taglib>

<taglib>
<taglib-uri> http://java.sun.com/jstl/core-rt </ taglib-uri>
<taglib-location> / WEB-INF/c-rt.tld </ taglib-location>
</ taglib>

<taglib>
<taglib-uri> http://java.sun.com/jstl/sql </ taglib-uri>
<taglib-location> / WEB-INF/sql.tld </ taglib-location>
</ taglib>

<taglib>
<taglib-uri> http://java.sun.com/jstl/sql-rt </ taglib-uri>
<taglib-location> / WEB-INF/sql-rt.tld </ taglib-location>
</ taglib>

<taglib>
<taglib-uri> http://java.sun.com/jstl/x </ taglib-uri>
<taglib-location> / WEB-INF/x.tld </ taglib-location>
</ taglib>

<taglib>
<taglib-uri> http://java.sun.com/jstl/x-rt </ taglib-uri>
<taglib-location> / WEB-INF/x-rt.tld </ taglib-location>
</ taglib>

(5) Failed to load or instantiate TagLibraryValidator class: org.apache.taglibs.standard.tlv.JstlCoreTLV
standard.jar not on the inside lib

(6) to create oracle table, the use of, role and comment keyword, it is recommended not to these two keywords as table names and field names.
Proposed to use toad or plsql developer to create tables, so software will be prompted to keywords.

(7) [ERROR] XMLHelper - Error parsing XML: XML InputStream (18) Attribute name "column" associated with an element type "key"

must be followed by the '=' character.
[ERROR] Configuration - Could not configure datastore from input stream <org.dom4j.DocumentException: Error on line 18 of

document: Attribute name "column" associated with an element type "key"

must be followed by the '=' character. Nested exception: Attribute name "column" associated with an element type "key" must

be followed by the '=' character.> org.dom4j.DocumentException: Error

on line 18 of document: Attribute name "column" associated with an element type "key" must be followed by the '='

character. Nested exception: Attribute name "column" associated with an element

type "key" must be followed by the '=' character.

xml syntax error, key grammar should be written like this <key column="id">

(8) hibernate3, the object of one side in one-to-many, we must write private Set pays = new HashSet ();, otherwise the packet mistake java.lang.NullPointerException,
And hibernate2 in private Set pays; not error;

(9) [DEBUG] AbstractSaveEventListener - generated identifier: 1, using strategy: org.hibernate.id.IncrementGenerator
org.hibernate.PropertyValueException: not-null property references a null or transient value: com.xxx.yyy.company
at org.hibernate.engine.Nullability.checkNullability (Nullability.java: 72)

<many to one> of the settings should be set to not-null = "false", set to not-null = "true" then the above error is reported

(10) org.hibernate.TransientObjectException: object references an unsaved transient instance - save the transient instance

before flushing: com.xxx.yyy.Company

Save at the same time also need to save the other table, and then flush ()

(11) Parse Fatal Error at line 12 column 1

struts-config.xml file is modified, a syntax error. Check grammar.

(12) org.hibernate.QueryException: could not resolve property: userid of:

com.xxx.yyy.Pay

Userid used when the foreign key must be used to get userinfo.userid Ways.

(13) javax.naming.NameNotFoundException: Name hibernate_connection_factory is not

bound in this Context reasons: hibernate mapping database. xml file has configuration errors, leading to hibernate_connection_factory unable to bind database.
Such as many-to-one set up after set up is still one of conflict <PROPERTY> property.

(14) [WARN] RequestProcessor - Unhandled Exception thrown: class java.lang.NullPointerException
Must be used to target new up.

(15) GROUP BY query expression must be met as follows:
select each of the following clause must appear in the group by clause, unless the use of aggregate functions.

(16) org.hibernate.TransientObjectException: object references an unsaved transient

instance - save the transient instance before flushing: com.xxx.yyy.Company

To cascade save, many times session.save ()
(17)
java.lang.IllegalArgumentException: id to load is required for loading
Reasons:

session.load (Company.class, payForm.getCompanyId ());
load () method of the second parameter must be searlizable, and must be a kind of mapping and database property value types in line, even if the cast will not work.

(18) [INFO] DefaultLoadEventListener - Error performing load command <org.hibernate.ObjectNotFoundException: No row with the

given identifier exists: [com.xxx.yyy.Company # 0]

> org.hibernate.ObjectNotFoundException: No row with the given identifier exists: [com.xxx.yyy.Company # 0]
That you are now the object of inquiry associated with the object of problem there is, generally because of data problems (the object associated with the object not found), data error, affected the normal execution process.

(19)
eclipse 3.1, myeclipse 4 error
Deployment is out of date due to changes in the underlying project contents. You'll need to mannally 'Redeploy' the project

to update the deployed archive.
Reasons
tomcat deploy a document the impact of the deployment of Access Denied.
After restart, remove the tomcat deploy document. Re-set to deploy in eclipse.
Why do I need to restart?
Since: google desktop software is for me to deploy a large 300MB file indexing, locking the large files, I guess google desktop index files required for this half of small

When the above. Therefore, eclipse can not be deployed over the past documents, to do first delete the job after the redeployment.

(20) ERROR LazyInitializationException: 19 - could not initialize proxy - the owning Session was closed
org.hibernate.LazyInitializationException: could not initialize proxy - the owning Session was closed
Solution.
cmpy = (CompanyEdit) ss.load (CompanyEdit.class, companyId1);
Hibernate.initialize (cmpy); / / mandatory to initialize cmpy, otherwise ss.close () after, cmpy will disappear.

(21) javascript error
Row: 56
Character: 45
Error: The End of the string is not constant
Code: 0

Questions are coded! Save after using ANSI encoding just fine.

(22) [WARN] JDBCExceptionReporter - SQL Error: 904, SQLState: 42000
[ERROR] JDBCExceptionReporter - ORA-00904: invalid column name [INFO] DefaultLoadEventListener - Error performing load command

<org.hibernate.exception.SQLGrammarException: could not load an entity: [com.xxx.yyy.Sellinfo # 1]

> org.hibernate.exception.SQLGrammarException: could not load an entity: [com.xxx.yyy.Sellinfo # 1]

***. hbm.xml file names and database to a different.

(23) ConnectionManager - unclosed connection, forgot to call close () on your session?

Reasons: there is no hibernate turn off the session's transaction. Or does not turn off session

(24) [WARN] SellCommentDAO - org.hibernate.ObjectDeletedException: deleted object would be re-saved by cascade (remove

deleted object from associations): [com.xxx.yyy.SellComment # 7]

Reasons: the father objects (one side) set the cascade = "save-update" directly delete child objects, it will error,
Ways deal: save necessary information cascade operation, delete the time have to apply the same principle.
SellComment sellComment = new SellComment ();
sellComment = (SellComment) session.load (SellComment.class, sellCommentId); / / obtain the son of the object
Long sellInfoId = sellComment.getSellInfo (). GetSellId ();// father to obtain id
SellInfo sellinfo = (SellInfo) session.load (SellInfo.class, sellInfoId); / / obtain the father objects
sellInfo.getSellComments (). remove (sellComment); / / sever the relationship between father and son
sellComment.setSellInfo (null); / / sever father son relationship
session.delete (sellComment); / / delete the son
session.flush ();

[ERROR] Configuration - Could not configure datastore from input stream <org.dom4j.DocumentException: Error on line 18 of

document: Attribute name "column" associated with an element type "key"

must be followed by the '=' character. Nested exception: Attribute name "column" associated with an element type "key" must

be followed by the '=' character.> org.dom4j.DocumentException: Error

on line 18 of document: Attribute name "column" associated with an element type "key" must be followed by the '='

character. Nested exception: Attribute name "column" associated with an element

type "key" must be followed by the '=' character.

xml syntax error, key grammar should be written like this <key column="id">

(8) hibernate3, the object of one side in one-to-many, we must write private Set pays = new HashSet ();, otherwise the packet mistake java.lang.NullPointerException,
And hibernate2 in private Set pays; not error;

(9) [DEBUG] AbstractSaveEventListener - generated identifier: 1, using strategy: org.hibernate.id.IncrementGenerator
org.hibernate.PropertyValueException: not-null property references a null or transient value: com.xxx.yyy.company
at org.hibernate.engine.Nullability.checkNullability (Nullability.java: 72)

<many to one> of the settings should be set to not-null = "false", set to not-null = "true" then the above error is reported

(10) org.hibernate.TransientObjectException: object references an unsaved transient instance - save the transient instance

before flushing: com.xxx.yyy.Company

Save at the same time also need to save the other table, and then flush ()

(11) Parse Fatal Error at line 12 column 1

struts-config.xml file is modified, a syntax error. Check grammar.

(12) org.hibernate.QueryException: could not resolve property: userid of:

com.xxx.yyy.Pay

Userid used when the foreign key must be used to get userinfo.userid Ways.

(13) javax.naming.NameNotFoundException: Name hibernate_connection_factory is not

bound in this Context reasons: hibernate mapping database. xml file has configuration errors, leading to hibernate_connection_factory unable to bind database.
Such as many-to-one set up after set up is still one of conflict <PROPERTY> property.

(14) [WARN] RequestProcessor - Unhandled Exception thrown: class java.lang.NullPointerException
Must be used to target new up.

(15) GROUP BY query expression must be met as follows:
select each of the following clause must appear in the group by clause, unless the use of aggregate functions.

(16) org.hibernate.TransientObjectException: object references an unsaved transient

instance - save the transient instance before flushing: com.xxx.yyy.Company

To cascade save, many times session.save ()
(17)
java.lang.IllegalArgumentException: id to load is required for loading
Reasons:

session.load (Company.class, payForm.getCompanyId ());
load () method of the second parameter must be searlizable, and must be a kind of mapping and database property value types in line, even if the cast will not work.

(18) [INFO] DefaultLoadEventListener - Error performing load command <org.hibernate.ObjectNotFoundException: No row with the

given identifier exists: [com.xxx.yyy.Company # 0]

> org.hibernate.ObjectNotFoundException: No row with the given identifier exists: [com.xxx.yyy.Company # 0]
That you are now the object of inquiry associated with the object of problem there is, generally because of data problems (the object associated with the object not found), data error, affected the normal execution process.

(19)
eclipse 3.1, myeclipse 4 error
Deployment is out of date due to changes in the underlying project contents. You'll need to mannally 'Redeploy' the project

to update the deployed archive.
Reasons
tomcat deploy a document the impact of the deployment of Access Denied.
After restart, remove the tomcat deploy document. Re-set to deploy in eclipse.
Why do I need to restart?
Since: google desktop software is for me to deploy a large 300MB file indexing, locking the large files, I guess google desktop index files required for this half of small

When the above. Therefore, eclipse can not be deployed over the past documents, to do first delete the job after the redeployment.

(20) ERROR LazyInitializationException: 19 - could not initialize proxy - the owning Session was closed
org.hibernate.LazyInitializationException: could not initialize proxy - the owning Session was closed
Solution.
cmpy = (CompanyEdit) ss.load (CompanyEdit.class, companyId1);
Hibernate.initialize (cmpy); / / mandatory to initialize cmpy, otherwise ss.close () after, cmpy will disappear.

(21) javascript error
Row: 56
Character: 45
Error: The End of the string is not constant
Code: 0

Questions are coded! Save after using ANSI encoding just fine.

(22) [WARN] JDBCExceptionReporter - SQL Error: 904, SQLState: 42000
[ERROR] JDBCExceptionReporter - ORA-00904: invalid column name [INFO] DefaultLoadEventListener - Error performing load command

<org.hibernate.exception.SQLGrammarException: could not load an entity: [com.xxx.yyy.Sellinfo # 1]

> org.hibernate.exception.SQLGrammarException: could not load an entity: [com.xxx.yyy.Sellinfo # 1]

***. hbm.xml file names and database to a different.

(23) ConnectionManager - unclosed connection, forgot to call close () on your session?

Reasons: there is no hibernate turn off the session's transaction. Or does not turn off session

(24) [WARN] SellCommentDAO - org.hibernate.ObjectDeletedException: deleted object would be re-saved by cascade (remove

deleted object from associations): [com.xxx.yyy.SellComment # 7]

Reasons: the father objects (one side) set the cascade = "save-update" directly delete child objects, it will error,
Ways deal: save necessary information cascade operation, delete the time have to apply the same principle.
SellComment sellComment = new SellComment ();
sellComment = (SellComment) session.load (SellComment.class, sellCommentId); / / obtain the son of the object
Long sellInfoId = sellComment.getSellInfo (). GetSellId ();// father to obtain id
SellInfo sellinfo = (SellInfo) session.load (SellInfo.class, sellInfoId); / / obtain the father objects
sellInfo.getSellComments (). remove (sellComment); / / sever the relationship between father and son
sellComment.setSellInfo (null); / / sever father son relationship
session.delete (sellComment); / / delete the son
session.flush ();

(5) different object with the same identifier value was already ... the problem
11:55 am 2009-02-06

About a different object with the same identifier value was already associated with the session's question

Wrong reasons: in hibernate inside with a session with the same logo but are two different entities.

I also encountered this problem, and a lot of online solutions, such as

One solution: session.clean ()

PS: If you clean behind the operation carried out saveOrUpdate (object), such as changing the data status of the operation, may have reported "Found two representations of same collection" abnormal.

Two solutions: session.refresh (object)

PS: When the object is not already in the database when the data object can not be used session.refresh (object) because the method of the session from hibernate go re-check in the object, if the session is not the object, so when the error will be you use saveOrUpdate (object) is also required before the judge you.

Three solutions: session.merge (object)

In fact, this problem should not be so resolved, as long as the same logo to find out that both are different entities, however, you deal with it, looking for things when it should be noted that the most likely use the current object entities have associated objects, such as, you get both at the same time user users, which belong to two user users have administrator permissions in the table type, (user table with the table belong to many-to-one relationship between competence) then, session that exist in both the administrator object, this object may be both an administrator permissions at the table is a data, but belong to two different user, this is the so-called same logo but are two different entities.

(26)
Anomaly 1: not-null property references a null or transient value
Solution: the "one-to-many" relationship of "one" side, not-null is set to false
(Reference: http://www.thearcmind.com/confluence/pages/viewpage.action?pageId=212)

Anomaly 2: org.hibernate.TransientObjectException: object references an unsaved transient instance
Solution: cascade = "save-update, persist"
(Reference: http://www.laliluna.de/254.html)

Anomaly 3: org.hibernate.QueryException: could not resolve property
Solution: "from Category category where category.userID =: userID" amended to read "from Category category where userID =: userID" or "from Category category where category.user.id =: userID"
(Reference: http://www.laliluna.de/277.html)

Anomaly 4: could not initialize proxy - the owning Session was closed
Solution: Set lazy for false
(Reference: http://forum.springframework.org/showthread.php?t=27993)

Abnormal 2 me in the application has encountered such a problem:

There are three tables: userInfo deptmentInfo role

UserInfo and deptmentInfo for many to one

UserInfo and role for the many to one

UserInfo for the preservation of the following object code:

DeptmentInfo dept = new DeptmentInfo ();
dept.setDeptName (deptName);

Role role = new Role ();
role.setRoleName (roleName);

UserInfo user = new UserInfo ();
user.setUserName (userName);
user.setUserSex (userSex);
user.setDuty (duty);
user.setPhone (phone);
user.setMobileNum (mobileNum);
user.setEmail (email);
user.setQq (qq);
user.setMsn (msn);
user.setAdress (adress);
user.setDeptmentInfo (dept);
user.setRole (role);

dao.save (user);

Implementation of mistake when there is: org.hibernate.TransientObjectException: object references an unsaved transient instance

Then changed to some place UserInfo.hbm.xml

As follows:

<many-to-one name = "role"
cascade = "save-update, persist" fetch = "select">
<column name="ROLE_ID" precision="22" scale="0" />
</ many-to-one>
<many-to-one name = "deptmentInfo"
cascade = "save-update, persist"
fetch = "select">
<column name="DEPT_ID" precision="22" scale="0" />
</ many-to-one>

Add the red part of the above, it OK, and can be preserved.