锘??xml version="1.0" encoding="utf-8" standalone="yes"?>136国产福利精品导航网址,成人一区二区三区,国产精品中文字幕在线观看http://www.aygfsteel.com/rain1102/category/37645.html<br/><font color="green" style="font-family: 鍗庢枃琛屾シ;font-size:16px;">瀛愭洶錛氬嵄閭︿笉鍏ワ紝涔遍偊涓嶅眳銆傚ぉ涓嬫湁閬撳垯瑙侊紝鏃犻亾鍒欓殣銆?lt;/font><font color="#3C1435"></font>zh-cnFri, 06 Nov 2009 16:43:16 GMTFri, 06 Nov 2009 16:43:16 GMT60AbstractTransactionalJUnit4SpringContextTests涓殑浜嬪姟鍥炴粴http://www.aygfsteel.com/rain1102/archive/2009/11/04/301147.htmlEric.ZhouEric.ZhouWed, 04 Nov 2009 12:58:00 GMThttp://www.aygfsteel.com/rain1102/archive/2009/11/04/301147.htmlhttp://www.aygfsteel.com/rain1102/comments/301147.htmlhttp://www.aygfsteel.com/rain1102/archive/2009/11/04/301147.html#Feedback0http://www.aygfsteel.com/rain1102/comments/commentRss/301147.htmlhttp://www.aygfsteel.com/rain1102/services/trackbacks/301147.html 褰撳墠鏈変竴涓猆ser鍜屼竴涓猂ole錛屽畠浠槸澶氬澶氬叧緋伙紝涓棿琛ㄤ負(fù)user_role瀛樻斁user鍜宺ole鐨刬d銆傞儴鍒哢ser浠g爜濡備笅錛?br /> @ManyToMany(cascade = { CascadeType.PERSIST }, fetch = FetchType.LAZY)   
    @JoinTable(name = "user_role",
      joinColumns = @JoinColumn(name = "user_id"),
      inverseJoinColumns = @JoinColumn(name = "role_id"))    

 public Set<Role> getRoles() {
  return roles;
 }
 
 public void setRoles(Set<Role> roles) {
  this.roles = roles;
 }
 
 public void addRole(Role role) {
  if (!this.roles.contains(role)) {
   this.roles.add(role);
  }
 }
 
 public void removeRole(Role role) {
  this.roles.remove(role);
 }

Role涓殑閮ㄥ垎浠g爜濡備笅錛?br /> @ManyToMany(
   cascade = {CascadeType.PERSIST, CascadeType.MERGE},
   mappedBy = "roles",
   targetEntity = User.class
   )

 public Set<User> getUsers() {
  return users;
 }

鑰屾祴璇曚唬鐮佺戶鎵夸簡AbstractTransactionalJUnit4SpringContextTests錛屼唬鐮佸涓嬶細(xì)
 @Test
 public void testManyToMany() {
  Role oneRole = new Role();
  oneRole.setDescription("manager");
  oneRole.setEnabled(true);
  oneRole.setRoleName("manger");
  
  Role twoRole = new Role();
  twoRole.setDescription("waitress");
  twoRole.setEnabled(true);
  twoRole.setRoleName("waitress");
  
  User user = new User();
  user.setEnabled(true);
  user.setPassword("jianghaiying");
  user.setUsername("Jiang HaiYing");
  user.addRole(oneRole);
  user.addRole(twoRole);
  userDAO.persist(user);
  
  try {
   userDAO.getConnection().commit();
  } catch (SQLException e) {
   e.printStackTrace();
  }
 }
榪欐牱鎵ц浠ュ悗錛屾墦鍗板嚭鐨勪俊鎭涓嬶細(xì)
Hibernate: insert into user (enabled, password, username) values (?, ?, ?)
Hibernate: insert into role (description, enabled, name) values (?, ?, ?)
Hibernate: insert into role (description, enabled, name) values (?, ?, ?)

榪欐椂鍊欓棶棰樺嚭鏉ヤ簡錛屼負(fù)浠涔堟病鏈夊線鍏崇郴琛ㄤ腑鎻掑叆鏁版嵁錛?br /> 鍏跺疄榪欏茍涓嶆槸浠g爜鎴栬呴厤緗啓閿欒浜嗭紝鍦ㄦ寮忚繍琛屼唬鐮佷竴鍒囨甯革紝鑰屾槸AbstractTransactionalJUnit4SpringContextTests鍑虹殑楝鹼紝浜嬪疄涓婂瀵瑰鍏寵仈鍏崇郴鏄敱Hibernate鍘誨府鎴戜滑緇存姢鐨勶紝鑰孉bstractTransactionalJUnit4SpringContextTests涓轟簡淇濇寔鏁版嵁鐨勬竻媧佸張浼?xì)鑷姩鍥炴粴銆傚浣曡В鍐寵繖涓棶棰樺憿錛?br /> 鏂規(guī)硶錛?br /> 鍙渶瑕佸湪test鏂規(guī)硶涓婃坊鍔?span style="color: #008000">@Rollback(false)錛?/span>涓嶈瀹冨洖婊氾紝涓鍒囨甯鎬簡銆傝繖鏃跺欎篃鍙互鍘繪帀try璇彞浜嗐?br /> Hibernate: insert into user (enabled, password, username) values (?, ?, ?)
Hibernate: insert into role (description, enabled, name) values (?, ?, ?)
Hibernate: insert into role (description, enabled, name) values (?, ?, ?)
Hibernate: insert into user_role (user_id, role_id) values (?, ?)
Hibernate: insert into user_role (user_id, role_id) values (?, ?)

Eric.Zhou 2009-11-04 20:58 鍙戣〃璇勮
]]>
欏圭洰涓皝瑁匰pring涓殑嫻嬭瘯鍩虹被http://www.aygfsteel.com/rain1102/archive/2008/04/21/194490.htmlEric.ZhouEric.ZhouMon, 21 Apr 2008 05:15:00 GMThttp://www.aygfsteel.com/rain1102/archive/2008/04/21/194490.htmlhttp://www.aygfsteel.com/rain1102/comments/194490.htmlhttp://www.aygfsteel.com/rain1102/archive/2008/04/21/194490.html#Feedback0http://www.aygfsteel.com/rain1102/comments/commentRss/194490.htmlhttp://www.aygfsteel.com/rain1102/services/trackbacks/194490.htmlpackage com.founder.common;

import Java.text.SimpleDateFormat;
import Java.util.TimeZone;

import org.hibernate.SessionFactory;
import org.springframework.test.AbstractTransactionalDataSourceSpringContextTests;

/**
 * This class is the base class of all the tests,
 * we can use the dependency injection functionality of spring in all the tests,
 * and the default transaction mode is rollback, so we don't need to write special code to restore data after calling some methods affected database data.
 *
 * @author Rui Zhou, Copyright © 2008 foundersoftware. All Rights Reserved.
 * @version 1.00, 2008-03-22 15:46
 */
public abstract class SpringTestCaseBase extends AbstractTransactionalDataSourceSpringContextTests {
 
 protected SimpleDateFormat sdf;
 
 public SpringTestCaseBase() {
  // query the protected variables to implement denpendency injection automatically,
  // so we don't need to write settor and gettor methods anymore.
  this.setPopulateProtectedVariables(true);
  
  sdf = new SimpleDateFormat("yyyy-MM-dd");
  sdf.setTimeZone(TimeZone.getDefault());
 }
 
 protected String[] getConfigLocations() {
  return new String[] { "file:WebRoot/WEB-INF/applicationContext*.xml"};
    }
 
 protected void flushSession(){
  SessionFactory sessionFactory = (SessionFactory)applicationContext.getBean("sessionFactory");  
        sessionFactory.getCurrentSession().flush();
    }
}



Eric.Zhou 2008-04-21 13:15 鍙戣〃璇勮
]]>
主站蜘蛛池模板: 石嘴山市| 南皮县| 滁州市| 邵东县| 蓬莱市| 普陀区| 桃源县| 双桥区| 和平区| 万全县| 克山县| 樟树市| 宜章县| 沾化县| 饶平县| 通山县| 长寿区| 恩施市| 乌兰浩特市| 玉树县| 阳西县| 政和县| 吕梁市| 香格里拉县| 平凉市| 五指山市| 鄢陵县| 疏勒县| 福鼎市| 扎囊县| 泰州市| 道孚县| 兴隆县| 云和县| 通山县| 鲁甸县| 平安县| 西乌珠穆沁旗| 开平市| 沙坪坝区| 疏勒县|