Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <hibernate-configuration>
- <session-factory>
- <!-- Database connection settings -->
- <property name="connection.driver_class">org.mm.mysql.Driver</property>
- <property name="connection.url">jdbc:mysql://localhost:3306</property>
- <property name="connection_userid">user</property>
- <property name="connection_pwd">pass</property>
- <!-- JDBC connection pool (use the built-in) -->
- <property name="connection_pool_size">true</property>
- <!-- SQL dialect -->
- <property name="dialect">org.hibernate.MySQLDialect</property>
- <!-- Disable the second-level cache -->
- <property name="cache.provider_class">org.hibernate.NoCacheProvider</property>
- <!-- Echo all executed SQL to stdout -->
- <property name="show_sql">1</property>
- <!-- Drop and re-create the database schema on startup -->
- <property name="hbmdl.auto">update</property>
- <!-- Names the annotated entity class -->
- <mapping class="com.test.springboot.model.AdultParticipant" />
- </session-factory>
- public static void main(String[] args) throws Exception {
- SpringApplication.run(WebApplication.class, args);
- Configuration cfg = new Configuration();
- cfg.configure("hibernate.cfg.xml");
- SessionFactory factory = cfg.buildSessionFactory();
- Session session = factory.openSession();
- Transaction t = session.beginTransaction();
- AdultParticipant ap = new AdultParticipant();
- ap.setFirstName("User");
- ap.setLastName("UserLastName");
- session.persist(ap);
- t.commit();
- session.close();
- System.out.println("successfully saved");
- @Entity
- @Table(name = "adultparticipant")
- public class AdultParticipant {
- @GeneratedValue
- @Id
- @Column (name = "id")
- private int id;
- @Column (name = "firstName")
- private String firstName;
- @Column (name = "lastName")
- private String lastName;
- public int getId() {
- return id;
- }
- public void setId(int id) {
- this.id = id;
- }
- public String getFirstName() {
- return firstName;
- }
- public void setFirstName(String firstName) {
- this.firstName = firstName;
- }
- public String getLastName() {
- return lastName;
- }
- public void setLastName(String lastName) {
- this.lastName = lastName;
- }
- }
- <?xml version="1.0" encoding="UTF-8"?>
- <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">
- <modelVersion>4.0.0</modelVersion>
- <artifactId>hello-springboot</artifactId>
- <name>hello-springboot</name>
- <description>hello-springboot</description>
- <packaging>war</packaging>
- <parent>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-starter-parent</artifactId>
- <version>1.3.5.RELEASE</version>
- </parent>
- <properties>
- <java.version>1.8</java.version>
- </properties>
- <dependencies>
- <dependency>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-starter-web</artifactId>
- </dependency>
- <dependency>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-starter-tomcat</artifactId>
- <scope>provided</scope>
- </dependency>
- <dependency>
- <groupId>org.apache.tomcat.embed</groupId>
- <artifactId>tomcat-embed-jasper</artifactId>
- <scope>provided</scope>
- </dependency>
- </dependencies>
- <build>
- <plugins>
- <plugin>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-maven-plugin</artifactId>
- </plugin>
- </plugins>
- </build>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement