Hibernate使用过程遇到的坑

版本5.1.0
使用Hibernate+JPA 注解
persistence.xml如下
注意:属性的name都是以hibernate开头

<?xml version="1.0" encoding="UTF-8"?>
<persistence version="1.0"
    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 persistence_1_0.xsd">
    <persistence-unit name="entityManager">
        <provider>org.hibernate.ejb.HibernatePersistence</provider>
        <properties>
            <property name="hibernate.archive.autodetection" value="class, hbm" />
            <property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect" />
            <property name="hibernate.connection.driver_class" value="com.mysql.jdbc.Driver" />
            <property name="hibernate.connection.url" value="jdbc:mysql://localhost:33067/hibernate" />
            <property name="hibernate.connection.username" value="root" />
            <property name="hibernate.connection.password" value="root" />
            <property name="hibernate.connection.provider_class"
                value="org.hibernate.connection.C3P0ConnectionProvider" />
            <property name="hibernate.c3p0.max_size" value="80" />
            <property name="hibernate.c3p0.min_size" value="5" />
            <property name="hibernate.c3p0.timeout" value="12000" />
            <property name="hibernate.c3p0.max_statements" value="1000" />
            <property name="hibernate.c3p0.idle_test_period" value="30000" />
            <property name="show_sql" value="true" />
            <property name="hibernate.hbm2ddl.auto" value="update" />
        </properties>
    </persistence-unit>
</persistence>

在使用注解的过程遇到的问题,name代表的名称
问题1、

@Entity
@Table(name = "msg")

这种注解会报错 javax.persistence.Table.indexes()[Ljavax/persistence/Index;
可以这样写

@Entity(name = "msg")

问题2:
在使用@ManyToOne(cascade = CascadeType.ALL)注解是不能使用@JoinColumn(name = “next_id”),否则会报javax.persistence.JoinColumn.foreignKey()Ljavax/persistence/ForeignKey;异常。不加joincolnum自动生成外键id名称即可。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值