Primary key attributes of Hibernate

Source: Internet
Author: User

Primary key attributes of Hibernate

You can directly query the api documentation when these attributes are used. However, api documentation may be difficult for beginners who have no experience.
This section describes how to generate the primary key of the ing file. It is important because Hibernate is used.
Entity class

package test.hibernate.hbmProperty;public class User {    private String id;    private String name;    public String getId() {        return id;    }    public void setId(String id) {        this.id = id;    }    public String getName() {        return name;    }    public void setName(String name) {        this.name = name;    }}

Test class

Package test. hibernate. hbmProperty; import org. hibernate. session; import org. hibernate. sessionFactory; import org. hibernate. cfg. configuration; import org. junit. test; public class App {private static SessionFactory sessionFactory = new Configuration ()//. configure ()//. addClass (User. class) // Add the Hibernate object class (load the corresponding ing file ). buildSessionFactory (); @ Test public void testSave () throws Exception {Session session = sessionFactory. openSession (); session. beginTransaction (); // ---------------------------------------------- // build Object User = new user (); // User. setId (UUID. randomUUID (). toString (); // id is set to String type user. setName (James); // Save the session. save (user); // session. save (new User (); // ------------------------------------------------ session. getTransaction (). commit (); session. close ();}}

Pay attention to some template code, such as session factory, opening session, and closing of transaction...
File Configuration


  
      
           
            
                
                 
                 
                 
                 
                 
                 
                 
             
            
        
    
   
  


The unique primary key ID of a database table can be incremental by Integer, or uudi, which is generated by the database with a unique ID of more than 30 characters.
Main configuration file hibernate. cfg. xml


      
           
            
    
     
Org. hibernate. dialect. MySQLDialect
            
    
     
Com. mysql. jdbc. Driver
            
    
     
Jdbc: mysql: // localhost: 3306/hibernate_2015
            
            
    
     
Root
            
    
     
686175
            
            
    
     
True
            
    
     
Update
            
        
   
  

 

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.