Hibernate connection sqlserver2000 Problem Resolution (parent-child relationship occurs while saving One-to-many & Many-to-one)

Source: Internet
Author: User
Tags manual integer sql server driver sql
server|sqlserver| Solve | The problem
Transorder:

OrderItem:

Test main () public static void main (string[] args) throws Hibernateexception {Sessions session = Hibernateutil.currentsessio  N ();      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 (102));   Order.getorderitems (). Add (item); Item.settransorder (order);

Session.save (order);    Session.flush ();  Tx.commit (); Hibernateutil.closesession (); }

Error message:

[Microsoft] [SQL Server Driver for JDBC] Can ' t start a cloned connection while in manual transaction mode.

Workaround:

Incredibly is the problem of MS, engaged for a few days, wasted,

Typically, you perform multiple statements operations on a JDBC connection on a SQL Server, or a manual transaction state (Autocommit=false) and use Direct (selectmethod=direct) mode. Direct mode is the default mode. Workaround when you use the manual transaction mode, you must set the value of the SelectMethod property to Cursor, or make sure that there is only one statement operation on your connection.

Set Hibernate.cfg.xml

jdbc:microsoft:sqlserver://localhost:1433; Selectmethod=cursor;databasename=yourdb

Selectmethod=cursor; The default is Selectmethod=diret;

I am in Hibernate syn Use, I also change. hibernatesynchronizer file, did not change hibernate.cfg.xml, hehe halo.

The best two files are changed, Hibernate.cfg.xml can be successfully run.




Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.