未创建Hibernate自动生成的SQL表

时间:2018-11-25 13:15:35

标签: java sql eclipse hibernate maven

嗨,谢谢大家阅读我的问题,

我正在Eclipse中的Maven项目中使用休眠模式,我的dbms是带有xampp的mysql。我的其中一个必须是数据库内部表的类没有在数据库中创建,不知道为什么。

javax.persistence.PersistenceException: org.hibernate.exception.SQLGrammarException: could not extract ResultSet
Caused by: java.sql.SQLSyntaxErrorException: Table 'db_p1_mdai.tuiteos' doesn't exist

这是我的自动生成的类/表的代码。

@Entity
@Table(name = "Tuiteos")
public class TuiteoVO implements Serializable{

private static final long serialVersionUID = 1L;

@Id
@GeneratedValue(generator = "increment")
@GenericGenerator(name="increment", strategy="increment")
private int id_tuiteo;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name="id_usuario_fk")
private UsuarioVO usuario_fk;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name="id_tuit_fk")
private TuitVO tuit_fk;

private boolean tuit_propio;

private boolean like;

private boolean retuit;

该类的其余部分包括一个哑类,构造函数,默认和参数化,getter,setter,equals和toString,所以我将跳过它。

这里是引用的类:

@Entity
@Table(name = "Usuarios")
public class UsuarioVO implements Serializable {

private static final long serialVersionUID = 1L;

@Id
@GeneratedValue(generator = "increment")
@GenericGenerator(name="increment", strategy="increment")
private int id_usuario;

private String nombre;

private String arroba;

private String correo;

private String password;

private String fechaRegistro;

private String descripcion;

@OneToMany(fetch = FetchType.LAZY, mappedBy = "id_usuario_emisor")
private Set<MensajeVO> mensajes;

@OneToMany(fetch = FetchType.LAZY, mappedBy = "usuario_fk")
private Set<TuiteoVO> tuiteos;

与Mensaje类的OneToMany关系可以很好地工作,所以我不会粘贴代码。

@Entity
@Table(name = "Tuits")
@Inheritance(strategy=InheritanceType.SINGLE_TABLE)
public class TuitVO implements Serializable {

private static final long serialVersionUID = 1L;

@Id
@GeneratedValue(generator = "increment")
@GenericGenerator(name="increment", strategy="increment")
protected int id_tuit;

protected String texto;

protected String fecha;

protected String hora;

protected int likes;

protected int retuits;

@ManyToMany(targetEntity = HashtagVO.class, cascade = { CascadeType.PERSIST, CascadeType.MERGE })
@JoinTable(name = "Tuit_Hashtag", joinColumns = @JoinColumn(name = "id_tuitt"), inverseJoinColumns = @JoinColumn(name = "id_hashtagg"))
protected Collection<HashtagVO> lista_hashtags;

@OneToMany(fetch = FetchType.LAZY, mappedBy = "tuit_fk")
protected Set<TuiteoVO> tuiteos;

最后,是persistence.xml:

<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_2_0.xsd"
    version="2.0">
    <persistence-unit name="es.unex.cum.mdai.*">
        <class>es.unex.cum.mdai.vo.UsuarioVO</class>
        <class>es.unex.cum.mdai.vo.TuitVO</class>
        <class>es.unex.cum.mdai.vo.HashtagVO</class>
        <class>es.unex.cum.mdai.vo.MensajeVO</class>
        <class>es.unex.cum.mdai.vo.TuiteoVO</class>
        <class>es.unex.cum.mdai.vo.TuitRespuestaVO</class>
        <properties>
            <property name="javax.persistence.jdbc.driver"
                value="com.mysql.jdbc.Driver" />
            <property name="javax.persistence.jdbc.url"
                value="jdbc:mysql://localhost:3306/DB_P1_MDAI?serverTimezone=UTC" />
            <property name="javax.persistence.jdbc.user" value="root" />
            <property name="javax.persistence.jdbc.password" value="" />
            <property name="hibernate.show_sql" value="true" />
            <property name="hibernate.hbm2ddl.auto" value="create" />
        </properties>
    </persistence-unit>
</persistence>

谢谢。

1 个答案:

答案 0 :(得分:0)

Okey,我得到了答案。经过一个周末的漫长研究,头痛,死亡愿望和问题没有解决的办法,最后我和我的老师交谈,他看到了问题,除了我是个白痴,问题还在。 。(鼓卷):

private boolean like;

我正在对自己进行一种sql注入,原因是“ like”是未创建SQL“ Tuiteos”表的保留字。我永远不会忘记这种经历。