Hibernate is connected to SQL Server2000 issues (One-to-Many & Many-to-One occurs when the parent-child relationship is save

xiaoxiao2021-03-06  18

Transorder:

ORDERITEM:

Test main () public static void main (String [] args) throws HibernateException {Session session = HibernateUtil.currentSession (); Transaction tx = session.beginTransaction (); TransOrder order = new TransOrder (); order.setAcceptType ( "www" ); Order.Setaddress ("Tom"); Order.SetCity ("Changzhou"); OrderItem Item = New ORDERITEM (); item.setItemcount (New Integer (100)); item.setItemMoney ("1200.2"); item. SetitemType ("kysj"); item.setPaperItemId (New Integer (101)); item.setResourceItemId (New Integer); Order.GetOrderItems (); add (item); item.setTransorder (Order);

Session.save (Order); session.flush (); tx.commit (); hibernateutil.closesis ();

Error Message:

.

Solution:

Actually the problem of MS, it took a few days, wasted,

Generally when you perform multiple statements on a SQL Server's JDBC, or manual transaction status (AutoCommit = false) and use Direct (SELECTMETHOD = Direct) mode. Direct mode is the default mode. Solution When you When using manual transaction mode, you must set the value of the SelectMethod property to Cursor, or make sure there is only one statement operation on your connection. Set hibernate.cfg.xml

JDBC: Microsoft: SQLServer: // localhost: 1433; selectMethod = Cursor; DatabaseName = YourDB

SELECTMETHOD = CURSOR; default is selectmethod = DIRET;

I am using it in Hibernate Syn, I have changed. HibernateSynchronizer file, did not change hibernate.cfg.xml, huh, halo.

It is best to change the two files, and hibernate.cfg.xml can run successfully.

转载请注明原文地址:https://www.9cbs.com/read-39549.html

New Post(0)