hibernate----1-1-----两表关联属性放在另一个表里面
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了hibernate----1-1-----两表关联属性放在另一个表里面,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含8133字,纯文字阅读大概需要12分钟。
内容图文
![hibernate----1-1-----两表关联属性放在另一个表里面](/upload/InfoBanner/zyjiaocheng/1233/ba288d3c2bff4cf6884ddcab2eb5e5ab.jpg)
package com.ij34.dao; import javax.persistence.*; @Entity @Table(name="Address_inf") publicclass Address{ @Id @Column(name="address_id") @GeneratedValue(strategy=GenerationType.IDENTITY) privateint addressId; private String message; @OneToOne(targetEntity=People.class) @JoinTable(name="people_address" ,joinColumns=@JoinColumn(name="addressId" ,referencedColumnName="address_id" ,unique=true) ,inverseJoinColumns=@JoinColumn(name="peopleId" ,referencedColumnName="people_id" ,unique=true) ) private People people; publicint getAddressId() { return addressId; } publicvoid setAddressId(int addressId) { this.addressId = addressId; } public String getMessage() { return message; } publicvoid setMessage(String message) { this.message = message; } public People getPeople() { return people; } publicvoid setPeople(People people) { this.people = people; } }
、
package com.ij34.dao; import javax.persistence.*; @Entity @Table(name="people_inf") public class People implements java.io.Serializable{ private static final long serialVersionUID = 1L; @Id @Column(name="people_id") @GeneratedValue(strategy=GenerationType.IDENTITY) private Integer id; private String name; private int age; @OneToOne(targetEntity=Address.class) @JoinTable(name="people_address" ,joinColumns=@JoinColumn(name="peopleId" ,referencedColumnName="people_id" ,unique=true) ,inverseJoinColumns=@JoinColumn(name="addressId" ,referencedColumnName="address_id" ,unique=true) ) private Address address; public Integer getId() { return id; } public void setId(Integer id) { this.id = id; } public String getName() { return name; } public void setName(String name) { this.name = name; } public int getAge() { return age; } public void setAge(int age) { this.age = age; } public Address getAddress() { return address; } public void setAddress(Address address) { this.address = address; } }
package com.ij34.web; import org.hibernate.Session; import org.hibernate.SessionFactory; import org.hibernate.Transaction; import org.hibernate.boot.registry.StandardServiceRegistryBuilder; import org.hibernate.cfg.Configuration; import org.hibernate.service.*; import com.ij34.dao.Address; import com.ij34.dao.People; publicclass test01 { publicstaticvoid main(String[] args)throws Exception { //实例化Configuration Configuration conf=new Configuration().configure(); ServiceRegistry SR=new StandardServiceRegistryBuilder().applySettings(conf.getProperties()).build(); // 以Configuration实例创建SessionFactory实例 SessionFactory SF=conf.buildSessionFactory(SR); //create session Session session=SF.openSession(); //start 事务 Transaction tx=session.beginTransaction(); People person = new People(); person.setAge(29); // 为复合主键的两个成员设置值 People people=new People(); people.setAge(22); people.setName("林彪"); Address a=new Address(); a.setMessage("广州"); a.setPeople(people); session.persist(a); session.save(people); tx.commit(); session.close(); SF.close(); } }
十月 16, 2016 11:11:12 下午 org.hibernate.annotations.common.reflection.java.JavaReflectionManager <clinit>
INFO: HCANN000001: Hibernate Commons Annotations {4.0.4.Final}
十月 16, 2016 11:11:12 下午 org.hibernate.Version logVersion
INFO: HHH000412: Hibernate Core {4.3.5.Final}
十月 16, 2016 11:11:12 下午 org.hibernate.cfg.Environment <clinit>
INFO: HHH000206: hibernate.properties not found
十月 16, 2016 11:11:12 下午 org.hibernate.cfg.Environment buildBytecodeProvider
INFO: HHH000021: Bytecode provider name : javassist
十月 16, 2016 11:11:12 下午 org.hibernate.cfg.Configuration configure
INFO: HHH000043: Configuring from resource: /hibernate.cfg.xml
十月 16, 2016 11:11:12 下午 org.hibernate.cfg.Configuration getConfigurationInputStream
INFO: HHH000040: Configuration resource: /hibernate.cfg.xml
十月 16, 2016 11:11:13 下午 org.hibernate.cfg.Configuration doConfigure
INFO: HHH000041: Configured SessionFactory: null
十月 16, 2016 11:11:13 下午 org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
WARN: HHH000402: Using Hibernate built-in connection pool (not for production use!)
十月 16, 2016 11:11:13 下午 org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator
INFO: HHH000401: using driver [com.mysql.jdbc.Driver] at URL [jdbc:mysql://localhost:3306/hibernate]
十月 16, 2016 11:11:13 下午 org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator
INFO: HHH000046: Connection properties: {user=root, password=****}
十月 16, 2016 11:11:13 下午 org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator
INFO: HHH000006: Autocommit mode: false
十月 16, 2016 11:11:13 下午 org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
INFO: HHH000115: Hibernate connection pool size: 20 (min=1)
Sun Oct 16 23:11:13 CST 2016 WARN: Establishing SSL connection without server‘s identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn‘t set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to ‘false‘. You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification.
十月 16, 2016 11:11:13 下午 org.hibernate.dialect.Dialect <init>
INFO: HHH000400: Using dialect: org.hibernate.dialect.MySQL5InnoDBDialect
十月 16, 2016 11:11:13 下午 org.hibernate.engine.transaction.internal.TransactionFactoryInitiator initiateService
INFO: HHH000399: Using default transaction strategy (direct JDBC transactions)
十月 16, 2016 11:11:13 下午 org.hibernate.hql.internal.ast.ASTQueryTranslatorFactory <init>
INFO: HHH000397: Using ASTQueryTranslatorFactory
十月 16, 2016 11:11:14 下午 org.hibernate.tool.hbm2ddl.SchemaUpdate execute
INFO: HHH000228: Running hbm2ddl schema update
十月 16, 2016 11:11:14 下午 org.hibernate.tool.hbm2ddl.SchemaUpdate execute
INFO: HHH000102: Fetching database metadata
十月 16, 2016 11:11:14 下午 org.hibernate.tool.hbm2ddl.SchemaUpdate execute
INFO: HHH000396: Updating schema
十月 16, 2016 11:11:14 下午 org.hibernate.tool.hbm2ddl.TableMetadata <init>
INFO: HHH000261: Table found: hibernate.address_inf
十月 16, 2016 11:11:14 下午 org.hibernate.tool.hbm2ddl.TableMetadata <init>
INFO: HHH000037: Columns: [address_id, message]
十月 16, 2016 11:11:14 下午 org.hibernate.tool.hbm2ddl.TableMetadata <init>
INFO: HHH000108: Foreign keys: []
十月 16, 2016 11:11:14 下午 org.hibernate.tool.hbm2ddl.TableMetadata <init>
INFO: HHH000126: Indexes: [primary]
十月 16, 2016 11:11:14 下午 org.hibernate.tool.hbm2ddl.TableMetadata <init>
INFO: HHH000261: Table found: hibernate.people_address
十月 16, 2016 11:11:14 下午 org.hibernate.tool.hbm2ddl.TableMetadata <init>
INFO: HHH000037: Columns: [peopleid, addressid]
十月 16, 2016 11:11:14 下午 org.hibernate.tool.hbm2ddl.TableMetadata <init>
INFO: HHH000108: Foreign keys: [fk_16h1wo9lfnwknsfcywssb636a, fk_aue0yqtcmxoo9hxc2cax44jg4]
十月 16, 2016 11:11:14 下午 org.hibernate.tool.hbm2ddl.TableMetadata <init>
INFO: HHH000126: Indexes: [fk_16h1wo9lfnwknsfcywssb636a, primary]
十月 16, 2016 11:11:14 下午 org.hibernate.tool.hbm2ddl.TableMetadata <init>
INFO: HHH000261: Table found: hibernate.people_inf
十月 16, 2016 11:11:14 下午 org.hibernate.tool.hbm2ddl.TableMetadata <init>
INFO: HHH000037: Columns: [people_id, name, age]
十月 16, 2016 11:11:14 下午 org.hibernate.tool.hbm2ddl.TableMetadata <init>
INFO: HHH000108: Foreign keys: []
十月 16, 2016 11:11:14 下午 org.hibernate.tool.hbm2ddl.TableMetadata <init>
INFO: HHH000126: Indexes: [primary]
十月 16, 2016 11:11:14 下午 org.hibernate.tool.hbm2ddl.SchemaUpdate execute
INFO: HHH000232: Schema update complete
Hibernate: insert into Address_inf (message) values (?)
Hibernate: insert into people_inf (age, name) values (?, ?)
Hibernate: insert into people_address (peopleId, addressId) values (?, ?)
十月 16, 2016 11:11:14 下午 org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl stop
INFO: HHH000030: Cleaning up connection pool [jdbc:mysql://localhost:3306/hibernate]
原文:http://www.cnblogs.com/tk55/p/5968185.html
内容总结
以上是互联网集市为您收集整理的hibernate----1-1-----两表关联属性放在另一个表里面全部内容,希望文章能够帮你解决hibernate----1-1-----两表关联属性放在另一个表里面所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。