toplink未创建一个表 [英] One table is not being created by toplink

查看:116
本文介绍了toplink未创建一个表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

不得不问这个,我感到非常愚蠢.但是我已经看了四个小时的代码了,无法弄清楚.我已经多次重建数据库,但无法正常工作. 由于某种原因未创建我的一张桌子.我有4个桌游戏,开发人员,gameimage和用户.不是在创建用户,而是在完美地创建另一个用户并且可以正常工作.我敢肯定这是一个愚蠢的错误,但我只是看不到它. 如果有人能告诉我为什么会这样,那太好了. 我正在使用toplink

I'm feeling really stupid having to ask this. But I've been looking at my code for 4 hours and can't figure it out. I have rebuild my database several times and can't get it to work. One of my tables isn't being created for some reason. I have 4 tables game, developer, gameimage and user. User isn't being created but the other are being created perfectly and working. I'm sure it's a stupid mistake but I just don't see it. If someone could just tell me why this might be happening that would be great. I'm using toplink

这是我的代码:

持久性xml:

<?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 http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd">
<persistence-unit name="GameDatabasePU" transaction-type="RESOURCE_LOCAL">
<provider>oracle.toplink.essentials.PersistenceProvider</provider>
<class>domainmodel.Game</class>
<class>domainmodel.GameImage</class>
<class>domainmodel.Developer</class>
<class>domainmodel.User</class>
<properties>
  <property name="toplink.jdbc.user" value="app"/>
  <property name="toplink.jdbc.password" value="app"/>
  <property name="toplink.jdbc.url" value="jdbc:derby://localhost:1527/Gamedatabase;create=true"/>
  <property name="toplink.jdbc.driver" value="org.apache.derby.jdbc.ClientDriver"/>
  <property name="toplink.ddl-generation" value="drop-and-create-tables"/>
</properties>
</persistence-unit>
</persistence>

用户:

@Entity
public class User {
    @Id
    private String username;
    private String password;
    private String firstName;
    private String surname;

    public User() {
    }

    public User(String naam, String pas){
        setUsername(naam);
        setPassword(pas);
    }

    public User(String naam, String pas, String firstName, String surname){
        setUsername(naam);
        setPassword(pas);
        setFirstName(firstName);
        setSurname(surname);
    }

    public void setUsername(String naam){
        this.username=naam;
    }
    //methods
}

推荐答案

不是真正的答案,但有更多技巧可以缩小问题范围.

Not realy an answer but more some tips to narrow the problem down.

1)尝试从persistence.xml中删除所有其他类(注释掉其他类的注释)

1) Try removing all other classes from your persistence.xml (comment out annotations on other classes)

问题可能出在另一个类中,并且输出令人误解.

Maybe the problem is in another class and the output is misleading.

2)尝试将调试/输出级别设置为另一个级别(DEBUG,FINE,FINEST),并让JPA提供程序公开查询.

2) Try setting the debug/output level to another level (DEBUG, FINE, FINEST) and get the JPA provider to expose queries.

对于TopLink,我认为将其添加到您的优先级属性部分中将达到目的:

For TopLink I think adding this to your prersistence properties section will do the trick:

<property name="toplink.logging.level" value="FINEST" />

3)您正在使用哪个数据库? MySql,PostgreSQL,HSQL,SQL服务器?

3) Which database are you using? MySql, PostgreSQL, HSQL, SQL-server?

某些数据库不(完全)支持某些功能.

Some databases don't (fully) support some things.

4)没关系,但是无论如何;

4) Shouldn't matter, but anyway;

@Table(name = "user")@Table(name = "usera")注释您的User类,这将确保表名不是问题.

Annotate your User class with @Table(name = "user") or @Table(name = "usera") this will make certain the table name isn't the problem.

这篇关于toplink未创建一个表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆