hibernate生成实体类怎么用注解的方式实现一个实体类

[一]、概述
本文大概讲述如何注解的方式实现one-to-many many-to-one的双向关联配置以及测试对实体CRUD基本操作,下面的演示以 Author (网络作者 为 one端)、Contact(联系方式 为many端)为例。
[二]、实体配置
Author.java
package com.micmiu.hibernate.demo.
import java.util.ArrayL
import java.util.L
import javax.persistence.CascadeT
import javax.persistence.C
import javax.persistence.E
import javax.persistence.GeneratedV
import javax.persistence.Id;
import javax.persistence.OneToM
import javax.persistence.OrderBy;
import javax.persistence.T
* 网络作者 (一对多的一)
* @author &a href="http://www.micmiu.com"&Michael&/a&
* @see &a href="http://www.micmiu.com"&http://www.micmiu.com&/a&
* @time Create on
上午9:35:14
* @version 1.0
@Table(name = "DEMO_T_AUTHOR")
public class Author {
private String sexT
private List&Contact& contacts = new ArrayList&Contact&();
@Column(name = "ID")
@GeneratedValue
public Long getId() {
@Column(name = "USERNAME")
public String getUsername() {
@Column(name = "TITLE")
public String getTitle() {
@OneToMany(cascade = CascadeType.ALL, mappedBy = "author")
@OrderBy("id")
public List&Contact& getContacts() {
@Column(name = "SEX_TYPE")
public String getSexType() {
return sexT
@Column(name = "DESCRIPTION")
public String getDescription() {
public void setId(Long id) {
public void setUsername(String username) {
this.username =
public void setTitle(String title) {
this.title =
public void setSexType(String sexType) {
this.sexType = sexT
public void setDescription(String description) {
this.description =
public void setContacts(List&Contact& contacts) {
this.contacts =
public String toString() {
return "Author [id=" + id + ", username=" + username + ", title="
+ title + ", sexType=" + sexType + ", description="
+ description + "]";
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
package com.micmiu.hibernate.demo.entity;&import java.util.ArrayList;import java.util.List;&import javax.persistence.CascadeType;import javax.persistence.Column;import javax.persistence.Entity;import javax.persistence.GeneratedValue;import javax.persistence.Id;import javax.persistence.OneToMany;import javax.persistence.OrderBy;import javax.persistence.Table;&/** * 网络作者 (一对多的一) *
* @author &a href="http://www.micmiu.com"&Michael&/a& * @see &a href="http://www.micmiu.com"&http://www.micmiu.com&/a& * @time Create on
上午9:35:14 * @version 1.0 */@Entity@Table(name = "DEMO_T_AUTHOR")public class Author {& private Long id;& private String username;& private String title;& private String sexType;& private String description;& private List<Contact> contacts = new ArrayList<Contact>();& @Id @Column(name = "ID") @GeneratedValue public Long getId() {
return id; }& @Column(name = "USERNAME") public String getUsername() {
return username; }& @Column(name = "TITLE") public String getTitle() {
return title; }& @OneToMany(cascade = CascadeType.ALL, mappedBy = "author") @OrderBy("id") public List<Contact> getContacts() {
return contacts; }& @Column(name = "SEX_TYPE") public String getSexType() {
return sexType; }& @Column(name = "DESCRIPTION") public String getDescription() {
return description; }& public void setId(Long id) {
this.id = id; }& public void setUsername(String username) {
this.username = username; }& public void setTitle(String title) {
this.title = title; }& public void setSexType(String sexType) {
this.sexType = sexType; }& public void setDescription(String description) {
this.description = description; }& public void setContacts(List<Contact> contacts) {
this.contacts = contacts; }& @Override public String toString() {
return "Author [id=" + id + ", username=" + username + ", title="
+ title + ", sexType=" + sexType + ", description="
+ description + "]"; }&}
Contact.java
package com.micmiu.hibernate.demo.
import javax.persistence.C
import javax.persistence.E
import javax.persistence.GeneratedV
import javax.persistence.Id;
import javax.persistence.JoinC
import javax.persistence.ManyToO
import javax.persistence.T
* 作者{@Author} 的联系方式 一对多的多
* @author &a href="http://www.micmiu.com"&Michael&/a&
* @time Create on
上午9:36:16
* @version 1.0
@Table(name = "DEMO_T_CONTACT")
public class Contact {
@Column(name = "ID")
@GeneratedValue
public Long getId() {
@Column(name = "TYPE")
public String getType() {
@Column(name = "DETAILS")
public String getDetails() {
@Column(name = "OTHER")
public String getOther() {
@ManyToOne
@JoinColumn(name = "AUTHOR_ID")
public Author getAuthor() {
public void setId(Long id) {
public void setAuthor(Author author) {
this.author =
public void setType(String type) {
this.type =
public void setDetails(String details) {
this.details =
public void setOther(String other) {
this.other =
public String toString() {
return "Contact [id=" + id + ", type=" + type + ", details=" + details
+ ", other=" + other + "]";
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
package com.micmiu.hibernate.demo.entity;&import javax.persistence.Column;import javax.persistence.Entity;import javax.persistence.GeneratedValue;import javax.persistence.Id;import javax.persistence.JoinColumn;import javax.persistence.ManyToOne;import javax.persistence.Table;&/** * 作者{@Author} 的联系方式 一对多的多 *
* @author &a href="http://www.micmiu.com"&Michael&/a& * @time Create on
上午9:36:16 * @version 1.0 */@Entity@Table(name = "DEMO_T_CONTACT")public class Contact {& private Long id;& private String type;& private String details;& private String other;& private Author author;& @Id @Column(name = "ID") @GeneratedValue public Long getId() {
return id; }& @Column(name = "TYPE") public String getType() {
return type; }& @Column(name = "DETAILS") public String getDetails() {
return details; }& @Column(name = "OTHER") public String getOther() {
return other; }& @ManyToOne @JoinColumn(name = "AUTHOR_ID") public Author getAuthor() {
return author; }& public void setId(Long id) {
this.id = id; }& public void setAuthor(Author author) {
this.author = author; }& public void setType(String type) {
this.type = type; }& public void setDetails(String details) {
this.details = details; }& public void setOther(String other) {
this.other = other; }& @Override public String toString() {
return "Contact [id=" + id + ", type=" + type + ", details=" + details
+ ", other=" + other + "]"; }&}
主要关注下代码中 @OneToMany @ManyToOne 两处配置。
[三]、单元测试
测试的类:OneToManyBidirectionalCRUDTest.java
package com.micmiu.
import java.util.ArrayL
import java.util.L
import org.hibernate.S
import org.hibernate.T
import org.junit.A
import org.junit.T
import com.micmiu.hibernate.demo.entity.A
import com.micmiu.hibernate.demo.entity.C
* 测试 注解配置双向一对多的CRUD
* @author &a href="http://www.micmiu.com"&Michael&/a&
* @see &a href="http://www.micmiu.com"&http://www.micmiu.com&/a&
* @time Create on
上午11:38:49
* @version 1.0
public class OneToManyBidirectionalCRUDTest extends AbstractHibernateBaseTest {
public void testMethod() {
long[] ids = testCreate();
testUpdate(ids);
testReadDelete(ids);
public long[] testCreate() {
System.out.println("&&&& 测试 添加");
Session session = sessionFactory.openSession();
Transaction tx = session.beginTransaction();
int beforeCountAuthor = session.createCriteria(Author.class).list()
int beforeCountContact = session.createCriteria(Contact.class).list()
Author author = new Author();
author.setUsername("test");
author.setTitle("测试人员");
author.setSexType("male");
author.setDescription("测试");
List&Contact& contacts = new ArrayList&Contact&();
Contact c1 = new Contact();
c1.setAuthor(author);
c1.setType("blog");
c1.setDetails("http://www.micmiu.com/author/test");
c1.setOther("");
contacts.add(c1);
Contact c2 = new Contact();
c2.setAuthor(author);
c2.setType("mail");
c2.setDetails("");
c2.setOther("");
contacts.add(c2);
// 双向1:N N:1 自动持久化关联的数据
author.setContacts(contacts);
session.save(author);
System.out.println("&&& one id = " + author.getId());
System.out.println("&&& many id = " + c1.getId());
System.out.println("&&& many id = " + c2.getId());
int expectedCountAuthor = session.createCriteria(Author.class).list()
int expectedCountContact = session.createCriteria(Contact.class).list()
Assert.assertEquals(expectedCountAuthor, beforeCountAuthor + 1);
Assert.assertEquals(expectedCountContact, beforeCountContact + 2);
tx.commit();
session.close();
return new long[] { author.getId(), c1.getId(), c2.getId() };
public void testUpdate(long[] ids) {
System.out.println("&&&& 测试 更新");
Session session = sessionFactory.openSession();
Transaction tx = session.beginTransaction();
long authorId = ids[0];
long contactId = ids[1];
long contact2Id = ids[2];
System.out.println("&&&& 更新 1:N中 N的数据");
Contact contact = (Contact) session.get(Contact.class, contactId);
System.out.println(contact);
contact.setOther("update");
session.update(contact);
Contact contact2 = (Contact) session.get(Contact.class, contactId);
System.out.println(contact2);
Assert.assertEquals("update", contact2.getOther());
System.out.println("&&&& 更新 1:N中 1的数据");
Author author = (Author) session.get(Author.class, authorId);
System.out.println(author);
author.setDescription("update");
List&Contact& contacts = author.getContacts();
List&Contact& removes = new ArrayList&Contact&();
for (Contact c : contacts) {
if (c.getId().longValue() == contact2Id) {
removes.add(c);
session.delete(c);
contacts.removeAll(removes);
Contact cn = new Contact();
cn.setAuthor(author);
cn.setType("blog");
cn.setDetails("http://www.micmiu.com/author/testnew");
cn.setOther("addnew");
contacts.add(cn);
author.setContacts(contacts);
session.update(author);
Author author2 = (Author) session.get(Author.class, authorId);
for (Contact c : author2.getContacts()) {
System.out.println(c);
Assert.assertEquals("update", author2.getDescription());
tx.commit();
session.close();
public void testReadDelete(long[] ids) {
System.out.println("&&&& 测试读取和删除");
Session session = sessionFactory.openSession();
Transaction tx = session.beginTransaction();
System.out.println("&&&& 查询初始");
int beforeCountAuthor = session.createCriteria(Author.class).list()
int beforeCountContact = session.createCriteria(Contact.class).list()
System.out.println("&&&& size
one = " + beforeCountAuthor + " many ="
+ beforeCountContact);
long authorId = ids[0];
long contactId = ids[1];
System.out.println("&&&& 查询 1:N中 N的数据");
Contact contact = (Contact) session.get(Contact.class, contactId);
System.out.println(contact);
Assert.assertEquals(contactId, contact.getId().longValue());
System.out.println("&&&& 删除1:N中 N的数据后,查询N的数据");
session.delete(contact);
int actualContactCount2 = session.createCriteria(Contact.class).list()
System.out.println("&&&& size many" + actualContactCount2);
Assert.assertEquals(beforeCountContact - 1, actualContactCount2);
System.out.println("&&&& 查询 1:N中 1的数据");
Author author = (Author) session.get(Author.class, authorId);
System.out.println(author);
Assert.assertEquals(authorId, author.getId().longValue());
System.out.println("&&&& 删除1:N中 1的数据后,查询1的数据");
session.delete(author);
int actualCountAuthor = session.createCriteria(Author.class).list()
System.out.println("&&&& size one = " + actualCountAuthor);
Assert.assertEquals(beforeCountAuthor - 1, actualCountAuthor);
System.out.println("&&&& 删除1:N中 1的数据后,查询N的数据");
int actualCountContact = session.createCriteria(Contact.class).list()
Assert.assertEquals(actualCountContact, beforeCountContact - 2);
System.out.println("&&&& size many = " + actualCountContact);
tx.commit();
session.close();
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
package com.micmiu.hibernate;&import java.util.ArrayList;import java.util.List;&import org.hibernate.Session;import org.hibernate.Transaction;import org.junit.Assert;import org.junit.Test;&import com.micmiu.hibernate.demo.entity.Author;import com.micmiu.hibernate.demo.entity.Contact;&/** *
* 测试 注解配置双向一对多的CRUD *
* @author &a href="http://www.micmiu.com"&Michael&/a& * @see &a href="http://www.micmiu.com"&http://www.micmiu.com&/a& * @time Create on
上午11:38:49 * @version 1.0 */public class OneToManyBidirectionalCRUDTest extends AbstractHibernateBaseTest {& @Override @Test public void testMethod() {
long[] ids = testCreate();
testUpdate(ids);
testReadDelete(ids); }& public long[] testCreate() {
System.out.println("&&&& 测试 添加");
Session session = sessionFactory.openSession();
Transaction tx = session.beginTransaction();&
int beforeCountAuthor = session.createCriteria(Author.class).list()
int beforeCountContact = session.createCriteria(Contact.class).list()
Author author = new Author();
author.setUsername("test");
author.setTitle("测试人员");
author.setSexType("male");
author.setDescription("测试");&
List<Contact> contacts = new ArrayList<Contact>();
Contact c1 = new Contact();
c1.setAuthor(author);
c1.setType("blog");
c1.setDetails("http://www.micmiu.com/author/test");
c1.setOther("");
contacts.add(c1);&
Contact c2 = new Contact();
c2.setAuthor(author);
c2.setType("mail");
c2.setDetails("");
c2.setOther("");
contacts.add(c2);&
// 双向1:N N:1 自动持久化关联的数据
author.setContacts(contacts);
session.save(author);&
System.out.println("&&& one id = " + author.getId());
System.out.println("&&& many id = " + c1.getId());
System.out.println("&&& many id = " + c2.getId());&
int expectedCountAuthor = session.createCriteria(Author.class).list()
int expectedCountContact = session.createCriteria(Contact.class).list()
Assert.assertEquals(expectedCountAuthor, beforeCountAuthor + 1);
Assert.assertEquals(expectedCountContact, beforeCountContact + 2);
tx.commit();
session.close();
return new long[] { author.getId(), c1.getId(), c2.getId() };& }& public void testUpdate(long[] ids) {
System.out.println("&&&& 测试 更新");
Session session = sessionFactory.openSession();
Transaction tx = session.beginTransaction();&
long authorId = ids[0];
long contactId = ids[1];
long contact2Id = ids[2];&
System.out.println("&&&& 更新 1:N中 N的数据");
Contact contact = (Contact) session.get(Contact.class, contactId);
System.out.println(contact);
contact.setOther("update");
session.update(contact);&
Contact contact2 = (Contact) session.get(Contact.class, contactId);
System.out.println(contact2);
Assert.assertEquals("update", contact2.getOther());&
System.out.println("&&&& 更新 1:N中 1的数据");
Author author = (Author) session.get(Author.class, authorId);
System.out.println(author);
author.setDescription("update");&
List<Contact> contacts = author.getContacts();
List<Contact> removes = new ArrayList<Contact>();
for (Contact c : contacts) {
if (c.getId().longValue() == contact2Id) {
removes.add(c);
session.delete(c);
contacts.removeAll(removes);&
Contact cn = new Contact();
cn.setAuthor(author);
cn.setType("blog");
cn.setDetails("http://www.micmiu.com/author/testnew");
cn.setOther("addnew");
contacts.add(cn);&
author.setContacts(contacts);
session.update(author);&
Author author2 = (Author) session.get(Author.class, authorId);
for (Contact c : author2.getContacts()) {
System.out.println(c);
Assert.assertEquals("update", author2.getDescription());&
tx.commit();
session.close(); }& public void testReadDelete(long[] ids) {&
System.out.println("&&&& 测试读取和删除");
Session session = sessionFactory.openSession();
Transaction tx = session.beginTransaction();
System.out.println("&&&& 查询初始");
int beforeCountAuthor = session.createCriteria(Author.class).list()
int beforeCountContact = session.createCriteria(Contact.class).list()
System.out.println("&&&& size&&one = " + beforeCountAuthor + " many ="
+ beforeCountContact);&
long authorId = ids[0];
long contactId = ids[1];&
System.out.println("&&&& 查询 1:N中 N的数据");
Contact contact = (Contact) session.get(Contact.class, contactId);
System.out.println(contact);
Assert.assertEquals(contactId, contact.getId().longValue());&
System.out.println("&&&& 删除1:N中 N的数据后,查询N的数据");
session.delete(contact);&
int actualContactCount2 = session.createCriteria(Contact.class).list()
System.out.println("&&&& size many" + actualContactCount2);
Assert.assertEquals(beforeCountContact - 1, actualContactCount2);&
System.out.println("&&&& 查询 1:N中 1的数据");
Author author = (Author) session.get(Author.class, authorId);
System.out.println(author);
Assert.assertEquals(authorId, author.getId().longValue());&
System.out.println("&&&& 删除1:N中 1的数据后,查询1的数据");
session.delete(author);
int actualCountAuthor = session.createCriteria(Author.class).list()
System.out.println("&&&& size one = " + actualCountAuthor);
Assert.assertEquals(beforeCountAuthor - 1, actualCountAuthor);&
System.out.println("&&&& 删除1:N中 1的数据后,查询N的数据");
int actualCountContact = session.createCriteria(Contact.class).list()
Assert.assertEquals(actualCountContact, beforeCountContact - 2);
System.out.println("&&&& size many = " + actualCountContact);&
tx.commit();
session.close(); }&}
AbstractHibernateBaseTest.java
package com.micmiu.
import org.hibernate.SessionF
import org.hibernate.cfg.C
import org.hibernate.service.ServiceR
import org.hibernate.service.ServiceRegistryB
import org.junit.AfterC
import org.junit.BeforeC
import org.junit.T
* 单元测试的抽象类
* @author &a href="http://www.micmiu.com"&Michael&/a&
* @time Create on
下午7:31:02
* @version 1.0
public abstract class AbstractHibernateBaseTest {
protected static SessionFactory sessionF
@BeforeClass
public static void beforeClass() {
Configuration configuration = new Configuration().configure();
ServiceRegistry serviceRegistry = new ServiceRegistryBuilder()
.applySettings(configuration.getProperties())
.buildServiceRegistry();
sessionFactory = configuration.buildSessionFactory(serviceRegistry);
@AfterClass
public static void afterClass() {
sessionFactory.close();
public abstract void testMethod();
12345678910111213141516171819202122232425262728293031323334353637383940
package com.micmiu.hibernate;&import org.hibernate.SessionFactory;import org.hibernate.cfg.Configuration;import org.hibernate.service.ServiceRegistry;import org.hibernate.service.ServiceRegistryBuilder;import org.junit.AfterClass;import org.junit.BeforeClass;import org.junit.Test;&/** * 单元测试的抽象类 *
* @author &a href="http://www.micmiu.com"&Michael&/a& * @time Create on
下午7:31:02 * @version 1.0 */public abstract class AbstractHibernateBaseTest {& protected static SessionFactory sessionFactory;& @BeforeClass public static void beforeClass() {
Configuration configuration = new Configuration().configure();
ServiceRegistry serviceRegistry = new ServiceRegistryBuilder()
.applySettings(configuration.getProperties())
.buildServiceRegistry();
sessionFactory = configuration.buildSessionFactory(serviceRegistry);& }& @AfterClass public static void afterClass() {
sessionFactory.close(); }& @Test public abstract void testMethod();&}
运行单元测试,所有测试均通过,详细日志如下:
&&&& 测试 添加
Hibernate:
this_.ID as ID2_0_,
this_.DESCRIPTION as DESCRIPT2_2_0_,
this_.SEX_TYPE as SEX3_2_0_,
this_.TITLE as TITLE2_0_,
this_.USERNAME as USERNAME2_0_
DEMO_T_AUTHOR this_
Hibernate:
this_.ID as ID3_1_,
this_.AUTHOR_ID as AUTHOR5_3_1_,
this_.DETAILS as DETAILS3_1_,
this_.OTHER as OTHER3_1_,
this_.TYPE as TYPE3_1_,
author2_.ID as ID2_0_,
author2_.DESCRIPTION as DESCRIPT2_2_0_,
author2_.SEX_TYPE as SEX3_2_0_,
author2_.TITLE as TITLE2_0_,
author2_.USERNAME as USERNAME2_0_
DEMO_T_CONTACT this_
left outer join
DEMO_T_AUTHOR author2_
on this_.AUTHOR_ID=author2_.ID
Hibernate:
hibernate_sequence.nextval
Hibernate:
hibernate_sequence.nextval
Hibernate:
hibernate_sequence.nextval
&&& one id = 75
&&& many id = 76
&&& many id = 77
Hibernate:
DEMO_T_AUTHOR
(DESCRIPTION, SEX_TYPE, TITLE, USERNAME, ID)
(?, ?, ?, ?, ?)
Hibernate:
DEMO_T_CONTACT
(AUTHOR_ID, DETAILS, OTHER, TYPE, ID)
(?, ?, ?, ?, ?)
Hibernate:
DEMO_T_CONTACT
(AUTHOR_ID, DETAILS, OTHER, TYPE, ID)
(?, ?, ?, ?, ?)
Hibernate:
this_.ID as ID2_0_,
this_.DESCRIPTION as DESCRIPT2_2_0_,
this_.SEX_TYPE as SEX3_2_0_,
this_.TITLE as TITLE2_0_,
this_.USERNAME as USERNAME2_0_
DEMO_T_AUTHOR this_
Hibernate:
this_.ID as ID3_1_,
this_.AUTHOR_ID as AUTHOR5_3_1_,
this_.DETAILS as DETAILS3_1_,
this_.OTHER as OTHER3_1_,
this_.TYPE as TYPE3_1_,
author2_.ID as ID2_0_,
author2_.DESCRIPTION as DESCRIPT2_2_0_,
author2_.SEX_TYPE as SEX3_2_0_,
author2_.TITLE as TITLE2_0_,
author2_.USERNAME as USERNAME2_0_
DEMO_T_CONTACT this_
left outer join
DEMO_T_AUTHOR author2_
on this_.AUTHOR_ID=author2_.ID
&&&& 测试 更新
&&&& 更新 1:N中 N的数据
Hibernate:
contact0_.ID as ID3_1_,
contact0_.AUTHOR_ID as AUTHOR5_3_1_,
contact0_.DETAILS as DETAILS3_1_,
contact0_.OTHER as OTHER3_1_,
contact0_.TYPE as TYPE3_1_,
author1_.ID as ID2_0_,
author1_.DESCRIPTION as DESCRIPT2_2_0_,
author1_.SEX_TYPE as SEX3_2_0_,
author1_.TITLE as TITLE2_0_,
author1_.USERNAME as USERNAME2_0_
DEMO_T_CONTACT contact0_
left outer join
DEMO_T_AUTHOR author1_
on contact0_.AUTHOR_ID=author1_.ID
contact0_.ID=?
Contact [id=76, type=blog, details=http://www.micmiu.com/author/test, other=null]
Contact [id=76, type=blog, details=http://www.micmiu.com/author/test, other=update]
&&&& 更新 1:N中 1的数据
Author [id=75, username=test, title=测试人员, sexType=male, description=测试]
Hibernate:
contacts0_.AUTHOR_ID as AUTHOR5_2_1_,
contacts0_.ID as ID3_1_,
contacts0_.ID as ID3_0_,
contacts0_.AUTHOR_ID as AUTHOR5_3_0_,
contacts0_.DETAILS as DETAILS3_0_,
contacts0_.OTHER as OTHER3_0_,
contacts0_.TYPE as TYPE3_0_
DEMO_T_CONTACT contacts0_
contacts0_.AUTHOR_ID=?
contacts0_.ID
Contact [id=76, type=blog, details=http://www.micmiu.com/author/test, other=update]
Contact [id=null, type=blog, details=http://www.micmiu.com/author/testnew, other=addnew]
Hibernate:
hibernate_sequence.nextval
Hibernate:
DEMO_T_CONTACT
(AUTHOR_ID, DETAILS, OTHER, TYPE, ID)
(?, ?, ?, ?, ?)
Hibernate:
DEMO_T_AUTHOR
DESCRIPTION=?,
SEX_TYPE=?,
USERNAME=?
Hibernate:
DEMO_T_CONTACT
AUTHOR_ID=?,
DETAILS=?,
Hibernate:
DEMO_T_CONTACT
&&&& 测试读取和删除
&&&& 查询初始
Hibernate:
this_.ID as ID2_0_,
this_.DESCRIPTION as DESCRIPT2_2_0_,
this_.SEX_TYPE as SEX3_2_0_,
this_.TITLE as TITLE2_0_,
this_.USERNAME as USERNAME2_0_
DEMO_T_AUTHOR this_
Hibernate:
this_.ID as ID3_1_,
this_.AUTHOR_ID as AUTHOR5_3_1_,
this_.DETAILS as DETAILS3_1_,
this_.OTHER as OTHER3_1_,
this_.TYPE as TYPE3_1_,
author2_.ID as ID2_0_,
author2_.DESCRIPTION as DESCRIPT2_2_0_,
author2_.SEX_TYPE as SEX3_2_0_,
author2_.TITLE as TITLE2_0_,
author2_.USERNAME as USERNAME2_0_
DEMO_T_CONTACT this_
left outer join
DEMO_T_AUTHOR author2_
on this_.AUTHOR_ID=author2_.ID
one = 4 many =10
&&&& 查询 1:N中 N的数据
Contact [id=76, type=blog, details=http://www.micmiu.com/author/test, other=update]
&&&& 删除1:N中 N的数据后,查询N的数据
Hibernate:
DEMO_T_CONTACT
Hibernate:
this_.ID as ID3_1_,
this_.AUTHOR_ID as AUTHOR5_3_1_,
this_.DETAILS as DETAILS3_1_,
this_.OTHER as OTHER3_1_,
this_.TYPE as TYPE3_1_,
author2_.ID as ID2_0_,
author2_.DESCRIPTION as DESCRIPT2_2_0_,
author2_.SEX_TYPE as SEX3_2_0_,
author2_.TITLE as TITLE2_0_,
author2_.USERNAME as USERNAME2_0_
DEMO_T_CONTACT this_
left outer join
DEMO_T_AUTHOR author2_
on this_.AUTHOR_ID=author2_.ID
&&&& size many9
&&&& 查询 1:N中 1的数据
Author [id=75, username=test, title=测试人员, sexType=male, description=update]
&&&& 删除1:N中 1的数据后,查询1的数据
Hibernate:
contacts0_.AUTHOR_ID as AUTHOR5_2_1_,
contacts0_.ID as ID3_1_,
contacts0_.ID as ID3_0_,
contacts0_.AUTHOR_ID as AUTHOR5_3_0_,
contacts0_.DETAILS as DETAILS3_0_,
contacts0_.OTHER as OTHER3_0_,
contacts0_.TYPE as TYPE3_0_
DEMO_T_CONTACT contacts0_
contacts0_.AUTHOR_ID=?
contacts0_.ID
Hibernate:
DEMO_T_CONTACT
Hibernate:
DEMO_T_AUTHOR
Hibernate:
this_.ID as ID2_0_,
this_.DESCRIPTION as DESCRIPT2_2_0_,
this_.SEX_TYPE as SEX3_2_0_,
this_.TITLE as TITLE2_0_,
this_.USERNAME as USERNAME2_0_
DEMO_T_AUTHOR this_
&&&& size one = 3
&&&& 删除1:N中 1的数据后,查询N的数据
Hibernate:
this_.ID as ID3_1_,
this_.AUTHOR_ID as AUTHOR5_3_1_,
this_.DETAILS as DETAILS3_1_,
this_.OTHER as OTHER3_1_,
this_.TYPE as TYPE3_1_,
author2_.ID as ID2_0_,
author2_.DESCRIPTION as DESCRIPT2_2_0_,
author2_.SEX_TYPE as SEX3_2_0_,
author2_.TITLE as TITLE2_0_,
author2_.USERNAME as USERNAME2_0_
DEMO_T_CONTACT this_
left outer join
DEMO_T_AUTHOR author2_
on this_.AUTHOR_ID=author2_.ID
&&&& size many = 8
本文介绍到此结束@.
原创文章,转载请注明: 转载自[
本文链接地址:
- 159,246 views - 106,181 views - 75,202 views - 72,952 views - 47,375 views - 41,930 views - 37,162 views - 33,634 views - 27,258 views - 23,832 views
2015年八月 &(1)
2015年三月 &(5)
2015年二月 &(3)
2015年一月 &(12)
2014年十二月 &(4)
2014年十一月 &(3)
2014年七月 &(1)
2014年五月 &(1)
2014年四月 &(12)
2014年三月 &(4)
2014年二月 &(6)
2014年一月 &(8)
2013年十二月 &(1)
2013年十月 &(9)
2013年九月 &(7)
2013年八月 &(8)
2013年六月 &(4)
2013年五月 &(4)
2013年四月 &(3)
2013年三月 &(10)
2013年二月 &(1)
2013年一月 &(2)
2012年十二月 &(1)
2012年十一月 &(7)
2012年十月 &(2)
2012年九月 &(4)
2012年八月 &(13)
2012年七月 &(14)
2012年六月 &(12)
2012年五月 &(15)
2012年四月 &(20)
2012年三月 &(22)
2012年二月 &(86)
标签云(3D)
WP Cumulus Flash tag cloud by
9 or better.

我要回帖

更多关于 hibernate注解方式 的文章

 

随机推荐