Java – does hibernate’s generator class really work?
After several hours of frustration with me and my eclipse, I raise this question here I hope to find some breathing opportunities here
I am trying to save POJO objects to MySQL database through hibernate 3.0 Basically, my requirement is: I need to assign an ID to the object before saving, rather than let hibernate do it for me
For this reason, I found and found < generator class = "assigned" / > in the document, which is very suitable for my bill So I passed hbm. The XML file updates the following ID:
<id name="id" type="int"> <column name="ID" /> <generator class="assigned" /> </id>
My POJO will hbm. XML file matches t
I'm setting all the parameters, including my POJO ID and calling hibernate's saveOrUpdate (object) method
If there is any help, the ID column of my database table has "auto Inc" disabled
Incredibly, when I looked at the contents of the database table, I inserted a row of Hibernate's own ID instead of what I set
How is that possible? Is there anything else that affects your ID card? Did I miss anything? What's your job?
My hibernate Properties are as follows (if it helps):
hibernate.connection.driver_class =com.MysqL.jdbc.Driver hibernate.dialect =org.hibernate.dialect.MysqLDialect hibernate.connection.url =jdbc:MysqL://localhost/dbdbdbdbdb hibernate.connection.username=root hibernate.connection.password=password hibernate.connection.pool_size=10 jdbc.batch_size=30 hibernate.show_sql=true hibernate.current_session_context_class=true hibernate.hbm2ddl.auto=validate hibernate.cglib.use_reflection_optimizer=false hibernate.generate_statistics=true hibernate.cache.use_query_cache=true hibernate.cache.region.factory_class=net.sf.ehcache.hibernate.EhCacheRegionFactory
Solution
All right, scam call the police! This is a real problem with eclipse Tomcat integration Before the HBM file takes effect, I must clean up the Tomcat directory and republish it
Tip: if you are running ant in eclipse, be sure to refresh the eclipse workspace from time to time Try to learn something