简体   繁体   中英

SQLSyntaxErrorException: Table/View does not exist

I'm getting a large stack trace which at its root is caused by: java.sql.SQLSyntaxErrorException: Table/View 'U' does not exist. Followed by an exception for everything that requires the entity: java.sql.SQLTransactionRollbackException: Constraint 'PSSVSERSRDTABASEID' is invalid: referenced table U does not exist.

I looked at this question and answer about a similar issue but it doesn't seem to address my particular problem. The reason being is when I open Database Development mode in Eclipse, I can see every other entity being mapped to a table, yet, not the entity User('U').

The User entity:

@Entity
@Inheritance(strategy = InheritanceType.JOINED)
@DiscriminatorColumn(name = "disc", discriminatorType = DiscriminatorType.STRING)
@Table(name = "U")
@NamedQuery(name = "FIND_WITH_USER_ID", query="SELECT DISTINCT u FROM User u WHERE u.userId = :userId")
public class User implements Serializable{
    private static final long serialVersionUID = 2468889149889625824L;
    @Id @GeneratedValue
    protected long databaseId;

    //getters/setters/etc

}

User does have a subclass (which shows up in the table schema):

@Entity
public class Customer extends User{
    private static final long serialVersionUID = -5239293307816318553L;

    public Customer(){
        super();
    } 

    //getters/setters/etc

}

In my persistence.xml file, I do specify for the tables to be created if they don't already exist:

<properties>
        <property name="javax.persistence.jdbc.driver" value="C:\Program Files\GlassFish\glassfish-4.1\glassfish4\javadb\lib\derby.jar"></property>
        <property name="javax.persistence.jdbc.url" value="jdbc:derby://localhost:1527/AppDB;create=true"></property>
        <property name="javax.persistence.schema-generation.database.action" value="drop-and-create"/>
</properties>

As stated, other tables are shown in the database schema (and pings to the database succeed). The problem seems to form around the User entity. I thought it might have had something to do with reserved keyword name clashes, so I changed the name of the table a few times (there seems to be a problem with Eclipse/Glassfish once I encounter this exception, even if I make changes, such as the name, and relaunch the app it doesn't update; out of scope of question I believe).

Why isn't a table being created for entity User? What am I missing? Why are the other tables being created still?

Problem is with you SQL script, you are passing the table alias name instead of column name. it should be u.

SELECT DISTINCT e.emp_id FROM Emp e

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM