One table is not being created by toplink

断了今生、忘了曾经 提交于 2019-12-13 04:44:33

问题


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

Here is my code:

persistence 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>

User:

@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
}

回答1:


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

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) Try setting the debug/output level to another level (DEBUG, FINE, FINEST) and get the JPA provider to expose queries.

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

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

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

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

4) Shouldn't matter, but anyway;

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



来源:https://stackoverflow.com/questions/10923904/one-table-is-not-being-created-by-toplink

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!