Java代码
public class ClassA{
public void save(TUser user){
session = sessionFactoryopenSession();
sessionsave(user);
sessionclose();
}
……
}
public class ClassB{
public void save (Order order){
session = sessionFactoryopenSession();
sessionsave(order);
sessionclose();
}
……
}
public class ClassC{
public void save(){
……
UserTransaction tx = new InitialContext()lookup(……);
classAsave(user);
classBsave(order);
txcommit();
……
}
}
public class ClassA{
public void save(TUser user){
session = sessionFactoryopenSession();
sessionsave(user);
sessionclose();
}
……
}
public class ClassB{
public void save (Order order){
session = sessionFactoryopenSession();
sessionsave(order);
sessionclose();
}
……
}
public class ClassC{
public void save(){
……
UserTransaction tx = new InitialContext()lookup(……);
classAsave(user);
classBsave(order);
txcommit();
……
}
}
上面代码中的ClassCsave方法也可以改成这样
Java代码
public class ClassC{
public void save(){
……
session = sessionFactoryopenSession();
Transaction tx = sessionbeginTransaction();
classAsave(user);
classBsave(order);
txcommit();
……
}
}
public class ClassC{
public void save(){
……
session = sessionFactoryopenSession();
Transaction tx = sessionbeginTransaction();
classAsave(user);
classBsave(order);
txcommit();
……
}
}
[] [] [] [] []