Hibernate ---- N-N -- (people and location), hibernaten1 Problem

Source: Internet
Author: User

Hibernate ---- N-N -- (people and location), hibernaten1 Problem

Package com. ij34.dao; import java. util. hashSet; import java. util. set; import javax. persistence. *; @ Entity @ Table (name = "people_inf") public class People implements java. io. serializable {private static final long serialVersionUID = 1L; @ Id @ Column (name = "lele_id") @ GeneratedValue (strategy = GenerationType. IDENTITY) private Integer id; private String name; private int age; @ ManyToMany (targetEntity = Address. class) // No mappedBy = "people" @ JoinTable (name = "people_address", joinColumns = @ JoinColumn (name = "peopleId ", referencedColumnName = "people_id"), inverseJoinColumns = @ JoinColumn (name = "addressId", referencedColumnName = "address_id") private Set <Address> address = new HashSet <> (); 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 Set <Address> getAddress () {return address;} public void setAddress (Set <Address> address) {this. address = address ;}}

 

Package com. ij34.dao; import java. util. hashSet; import java. util. set; import javax. persistence. *; @ Entity @ Table (name = "Address_inf") public class Address {@ Id @ Column (name = "address_id") @ GeneratedValue (strategy = GenerationType. IDENTITY) private int addressId; private String message; @ ManyToMany (targetEntity = People. class) @ JoinTable (name = "people_address", joinColumns = @ JoinColumn (name = "addressId", referencedColumnName = "address_id") // do not unique = true, inverseJoinColumns = @ JoinColumn (name = "peopleId", referencedColumnName = "people_id") private Set <People> people = new HashSet <> (); public int getAddressId () {return addressId;} public void setAddressId (int addressId) {this. addressId = addressId;} public String getMessage () {return message;} public void setMessage (String message) {this. message = message;} public Set <People> getPeople () {return people;} public void setPeople (Set <People> people) {this. people = people ;}}

 

 

****

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; public class test01 {public static void main (String [] args) throws Exception {// instantiate Configuration conf = new Configuration (). configure (); ServiceRegistry SR = new StandardServiceRegistryBuilder (). applySettings (conf. getProperties ()). build (); // create SessionFactory instance SessionFactory SF = conf in the Configuration instance. buildSessionFactory (SR); // create session Session session = SF. openSession (); // start Transaction tx = session. beginTransaction (); People person = new People (); person. setAge (29); // set the value of People people = new People (); people. setAge (22); people. setName ("Lin Biao"); // persistent People object (corresponding to inserting a master table record) session. save (people); Address a = new Address ();. setMessage ("Guangzhou");. getPeople (). add (people); session. persist (a); Address a2 = new Address (); a2.setMessage ("Hong Kong"); a2.getPeople (). add (people); session. persist (a2); People people2 = new People (); people2.setAge (17); people2.setName ("Xiao Fang"); people2.getAddress (). add (a2); session. save (people2); tx. commit (); session. close (); SF. close ();}}

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

**************************************** ***********************************

October 17 1:48:19 am org. hibernate. annotations. common. reflection. java. JavaReflectionManager <clinit>
INFO: HCANN000001: Hibernate Commons Annotations {4.0.4.Final}
October 17 1:48:19 am org. hibernate. Version logVersion
INFO: HHH000412: Hibernate Core {4.3.5.Final}
October 17 1:48:19 org. hibernate. cfg. Environment <clinit>
INFO: HHH000206: hibernate. properties not found
October 17 1:48:19 am org. hibernate. cfg. Environment buildBytecodeProvider
INFO: HHH000021: Bytecode provider name: javassist
October 17 1:48:19 am org. hibernate. cfg. Configuration configure
INFO: HHH000043: Processing ing from resource:/hibernate. cfg. xml
October 17 1:48:19 am org. hibernate. cfg. Configuration getConfigurationInputStream
INFO: HHH000040: Configuration resource:/hibernate. cfg. xml
October 17 1:48:19 am org. hibernate. cfg. Configuration doConfigure
INFO: HHH000041: Configured SessionFactory: null
October 17 1:48:19 am org. hibernate. engine. jdbc. connections. internal. DriverManagerConnectionProviderImpl configure
WARN: HHH000402: Using Hibernate built-in connection pool (not for production use !)
October 17 1:48:19 am org. hibernate. engine. jdbc. connections. internal. DriverManagerConnectionProviderImpl buildCreator
INFO: HHH000401: using driver [com. mysql. jdbc. Driver] at URL [jdbc: mysql: // localhost: 3306/hibernate]
October 17 1:48:19 am org. hibernate. engine. jdbc. connections. internal. DriverManagerConnectionProviderImpl buildCreator
INFO: HHH000046: Connection properties: {user = root, password = ****}
October 17 1:48:19 am org. hibernate. engine. jdbc. connections. internal. DriverManagerConnectionProviderImpl buildCreator
INFO: HHH000006: Autocommit mode: false
October 17 1:48:19 am org. hibernate. engine. jdbc. connections. internal. DriverManagerConnectionProviderImpl configure
INFO: HHH000115: Hibernate connection pool size: 20 (min = 1)
Mon Oct 17 01:48:19 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.
October 17 1:48:19 org. hibernate. dialect. Dialect <init>
INFO: HHH000400: Using dialect: org. hibernate. dialect. MySQL5InnoDBDialect
October 17 1:48:20 am org. hibernate. engine. transaction. internal. TransactionFactoryInitiator initiateService
INFO: HHH000399: Using default transaction strategy (direct JDBC transactions)
October 17 1:48:20 am org. hibernate. hql. internal. ast. ASTQueryTranslatorFactory <init>
INFO: HHH000397: Using ASTQueryTranslatorFactory
October 17 1:48:20 am org. hibernate. tool. hbm2ddl. SchemaUpdate execute
INFO: HHH000228: Running hbm2ddl schema update
October 17 1:48:20 am org. hibernate. tool. hbm2ddl. SchemaUpdate execute
INFO: HHH000102: Fetching database metadata
October 17 1:48:20 am org. hibernate. tool. hbm2ddl. SchemaUpdate execute
INFO: HHH000396: Updating schema
October 17 1:48:20 am org. hibernate. tool. hbm2ddl. DatabaseMetadata getTableMetadata
INFO: HHH000262: Table not found: Address_inf
October 17 1:48:20 am org. hibernate. tool. hbm2ddl. DatabaseMetadata getTableMetadata
INFO: HHH000262: Table not found: people_address
October 17 1:48:20 am org. hibernate. tool. hbm2ddl. DatabaseMetadata getTableMetadata
INFO: HHH000262: Table not found: people_inf
October 17 1:48:20 am org. hibernate. tool. hbm2ddl. DatabaseMetadata getTableMetadata
INFO: HHH000262: Table not found: Address_inf
October 17 1:48:20 am org. hibernate. tool. hbm2ddl. DatabaseMetadata getTableMetadata
INFO: HHH000262: Table not found: people_address
October 17 1:48:20 am org. hibernate. tool. hbm2ddl. DatabaseMetadata getTableMetadata
INFO: HHH000262: Table not found: people_inf
October 17 1:48:20 am org. hibernate. tool. hbm2ddl. DatabaseMetadata getTableMetadata
INFO: HHH000262: Table not found: Address_inf
October 17 1:48:20 am org. hibernate. tool. hbm2ddl. DatabaseMetadata getTableMetadata
INFO: HHH000262: Table not found: people_address
October 17 1:48:20 am org. hibernate. tool. hbm2ddl. DatabaseMetadata getTableMetadata
INFO: HHH000262: Table not found: people_inf
October 17 1:48:23 am org. hibernate. tool. hbm2ddl. SchemaUpdate execute
INFO: HHH000232: Schema update complete
Hibernate: insert into lele_inf (age, name) values (?, ?)
Hibernate: insert into Address_inf (message) values (?)
Hibernate: insert into Address_inf (message) values (?)
Hibernate: insert into lele_inf (age, name) values (?, ?)
Hibernate: insert into people_address (addressId, peopleId) values (?, ?)
Hibernate: insert into people_address (addressId, peopleId) values (?, ?)
Hibernate: insert into people_address (peopleId, addressId) values (?, ?)
October 17 1:48:23 am org. hibernate. engine. jdbc. connections. internal. DriverManagerConnectionProviderImpl stop
INFO: HHH000030: Cleaning up connection pool [jdbc: mysql: // localhost: 3306/hibernate]

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.