简体   繁体   中英

After adding a member a class, JPA crashes with a SQLSyntaxErrorException. How do I delete traces of the old class?

I created this project in Netbeans and it's the only way I know to access any of it. I can't seem to find the database where my objects are stored so that I may delete them. In fact, I it's best if it simply deletes everything every time I restart glassfish. I understand that changing a class would result in this kind of problem, but I don't know how to remove information about the old version of the class. Until now I've tried to work around the problem by refactoring the class name each time it changes but I've run out of creative names.

The exception:

javax.servlet.ServletException: Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.3.2.v20111125-r10461): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: java.sql.SQLSyntaxErrorException: Column 'CURRENTDAY' is either not in any table in the FROM list or appears within a join specification and is outside the scope of the join specification or appears in a HAVING clause and is not in the GROUP BY list. If this is a CREATE or ALTER TABLE  statement then 'CURRENTDAY' is not a column in the target table.
Error Code: -1
Call: SELECT ID, CURRENTDAY, INTERNAL_TIME_M, LASTTIME_M FROM FASTINTERNALCLOCK WHERE (ID = ?)
    bind => [1 parameter bound]
Query: ReadObjectQuery(name="readObject" referenceClass=FastInternalClock sql="SELECT ID, CURRENTDAY, INTERNAL_TIME_M, LASTTIME_M FROM FASTINTERNALCLOCK WHERE (ID = ?)")

What I have made of this is that the new CURRENTDAY member of class FASTINTERNALCLOCK is not in the table it's looking for it for, probably because it's looking in a table based on the old version of the class where the member was not yet present. How can I delete this table so that it may be recreated with the new member in mind?

persistence.xml:

<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.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_2_0.xsd">
  <persistence-unit name="webThermosPU" transaction-type="JTA">
    <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
    <jta-data-source>jdbc/__default</jta-data-source>
    <exclude-unlisted-classes>false</exclude-unlisted-classes>
    <properties>
      <property name="eclipselink.ddl-generation" value="create-tables"/>
    </properties>
  </persistence-unit>
</persistence>

您的SQL安装程序应该随附一个WorkBench程序,您可以使用该程序来访问数据库,并在需要时从数据库中删除表和/或行。

Try using the values"drop-and-create-tables" for DDL to drop and the create tables on deployment. Glashfish sets up a default __datasource on an embedded derby database as described here http://docs.oracle.com/cd/E18930_01/html/821-2424/gksmw.html

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