Advertisement
Guest User

Untitled

a guest
Mar 13th, 2017
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.50 KB | None | 0 0
  1. <hibernate-configuration>
  2. <session-factory>
  3. <!-- Database connection settings -->
  4. <property name="connection.driver_class">org.mm.mysql.Driver</property>
  5. <property name="connection.url">jdbc:mysql://localhost:3306</property>
  6. <property name="connection_userid">user</property>
  7. <property name="connection_pwd">pass</property>
  8.  
  9. <!-- JDBC connection pool (use the built-in) -->
  10. <property name="connection_pool_size">true</property>
  11.  
  12. <!-- SQL dialect -->
  13. <property name="dialect">org.hibernate.MySQLDialect</property>
  14.  
  15. <!-- Disable the second-level cache -->
  16. <property name="cache.provider_class">org.hibernate.NoCacheProvider</property>
  17.  
  18. <!-- Echo all executed SQL to stdout -->
  19. <property name="show_sql">1</property>
  20.  
  21. <!-- Drop and re-create the database schema on startup -->
  22. <property name="hbmdl.auto">update</property>
  23.  
  24. <!-- Names the annotated entity class -->
  25. <mapping class="com.test.springboot.model.AdultParticipant" />
  26.  
  27. </session-factory>
  28.  
  29. public static void main(String[] args) throws Exception {
  30. SpringApplication.run(WebApplication.class, args);
  31.  
  32. Configuration cfg = new Configuration();
  33. cfg.configure("hibernate.cfg.xml");
  34. SessionFactory factory = cfg.buildSessionFactory();
  35.  
  36. Session session = factory.openSession();
  37. Transaction t = session.beginTransaction();
  38.  
  39. AdultParticipant ap = new AdultParticipant();
  40. ap.setFirstName("User");
  41. ap.setLastName("UserLastName");
  42.  
  43. session.persist(ap);
  44.  
  45. t.commit();
  46.  
  47. session.close();
  48. System.out.println("successfully saved");
  49.  
  50. @Entity
  51. @Table(name = "adultparticipant")
  52. public class AdultParticipant {
  53.  
  54. @GeneratedValue
  55. @Id
  56. @Column (name = "id")
  57. private int id;
  58.  
  59. @Column (name = "firstName")
  60. private String firstName;
  61.  
  62. @Column (name = "lastName")
  63. private String lastName;
  64.  
  65.  
  66. public int getId() {
  67. return id;
  68. }
  69. public void setId(int id) {
  70. this.id = id;
  71. }
  72.  
  73.  
  74. public String getFirstName() {
  75. return firstName;
  76. }
  77. public void setFirstName(String firstName) {
  78. this.firstName = firstName;
  79. }
  80.  
  81. public String getLastName() {
  82. return lastName;
  83. }
  84. public void setLastName(String lastName) {
  85. this.lastName = lastName;
  86. }
  87. }
  88.  
  89. <?xml version="1.0" encoding="UTF-8"?>
  90. <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  91. <modelVersion>4.0.0</modelVersion>
  92. <artifactId>hello-springboot</artifactId>
  93. <name>hello-springboot</name>
  94. <description>hello-springboot</description>
  95. <packaging>war</packaging>
  96. <parent>
  97. <groupId>org.springframework.boot</groupId>
  98. <artifactId>spring-boot-starter-parent</artifactId>
  99. <version>1.3.5.RELEASE</version>
  100. </parent>
  101.  
  102. <properties>
  103. <java.version>1.8</java.version>
  104. </properties>
  105.  
  106. <dependencies>
  107. <dependency>
  108. <groupId>org.springframework.boot</groupId>
  109. <artifactId>spring-boot-starter-web</artifactId>
  110. </dependency>
  111.  
  112. <dependency>
  113. <groupId>org.springframework.boot</groupId>
  114. <artifactId>spring-boot-starter-tomcat</artifactId>
  115. <scope>provided</scope>
  116. </dependency>
  117.  
  118. <dependency>
  119. <groupId>org.apache.tomcat.embed</groupId>
  120. <artifactId>tomcat-embed-jasper</artifactId>
  121. <scope>provided</scope>
  122. </dependency>
  123. </dependencies>
  124. <build>
  125. <plugins>
  126. <plugin>
  127. <groupId>org.springframework.boot</groupId>
  128. <artifactId>spring-boot-maven-plugin</artifactId>
  129. </plugin>
  130. </plugins>
  131. </build>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement