小编vla*_* dd的帖子

简单的H2和Hibernate/JPA

使用H2作为数据库,JPA和Hibernate进行简单测试.没有明确的错误,但它不会持久存在.我肯定错过了一些非常简单的事情

META-INF /中的persistence.xml:

<?xml version="1.0" encoding="UTF-8" ?>
<persistence xmlns="http://java.sun.com/xml/ns/persistence"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://java.sun.com/xml/ns/persistence
 http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd" version="1.0">

  <persistence-unit name="thePersistenceUnit" transaction-type="RESOURCE_LOCAL">
     <provider>org.hibernate.ejb.HibernatePersistence</provider>

    <class>entities.Person</class>

    <properties>
        <property name="connection.driver_class" value="org.h2.Driver"/>
        <property name="hibernate.connection.url" value="jdbc:h2:./db/repository"/>
        <property name="hibernate.dialect" value="org.hibernate.dialect.H2Dialect"/>
        <property name="hibernate.hbm2ddl.auto" value="create-drop"/>
        <property name="hibernate.show_sql" value="true" />

    </properties>
</persistence-unit>
Run Code Online (Sandbox Code Playgroud)

简单的实体:

@Entity
public class Person {

    @Id
    @GeneratedValue
    private Integer id;
    private String firstName;

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }


    public String getFirstName() {
        return firstName;
    }

    public void setFirstName(String firstName) {
        this.firstName …
Run Code Online (Sandbox Code Playgroud)

hibernate jpa h2

13
推荐指数
1
解决办法
5万
查看次数

标签 统计

h2 ×1

hibernate ×1

jpa ×1