org.h2.jdbc.JdbcSQLException:找不到架构“CLASSES”

时间:2015-11-11 19:51:34

标签: java-ee jpa eclipselink

我构建了一个成功插入数据库的JPA应用程序。然后我构建了一个工作正常的Java EE Web应用程序。然后,我尝试将JPA应用程序中的相同文件添加到Java EE Web应用程序中。出于某种原因,即使JPA应用程序像冠军一样工作,Java EE Web应用程序中的相同文件也会抛出:

内部异常:org.h2.jdbc.JdbcSQLException:未找到架构“CLASSES”; SQL语句: INSERT INTO classes.classes(id,associated_term,credit_hours,days,description,instructor_name,lab_info,location,name,registration_levels,schedule_type,seats_available,time,type)VALUES(?,?,?,?,?,?,?, ?,?,?,?,?,?,?)[90079-173]

旁注,我有一个名为“classes”的模式,以及一个名为“classes”的模式中的表。我在两个应用程序中使用完全相同的persistence.xml文件...怎么可以做得很好,另一个无法识别CLASSES模式?我迷糊了。这里有更多信息...

Project Structure

来自persistence.xml:

<persistence-unit name="JPADemo">
    <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
    <class>com.jared.tutoring.model.courses.Classes</class>
    <exclude-unlisted-classes>false</exclude-unlisted-classes>

    <properties>
        <property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver" />
        <property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:3306/classes" />
        <property name="javax.persistence.jdbc.user" value="root" />
        <property name="javax.persistence.jdbc.password" value="letmein!" />

        <!-- EclipseLink should create the database schema automatically -->
        <property name="eclipselink.ddl-generation" value="create-tables" />
        <property name="eclipselink.ddl-generation.output-mode" value="database" />
        <property name="eclipselink.logging.level" value="SEVERE" />
    </properties>

</persistence-unit>

来自Bean.java

import javax.faces.bean.ManagedBean;
import com.jared.jpa.demo.JpaTest;

@ManagedBean
public class Bean {

    public void doDbStuff() {
        JpaTest jpaTest = new JpaTest();
        jpaTest.doDBStuff();
    }

}

来自Classes.java

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;

/**
 * Classes generated by hbm2java
 */
@Entity
@Table(name = "classes", catalog = "classes")
public class Classes implements java.io.Serializable {

    private String id;
    private String name;
    private String description;
    private String associatedTerm;
    private String registrationLevels;
    private String creditHours;
    private String instructorName;
    private String location;
    private String labInfo;
    private String days;
    private String time;
    private String scheduleType;
    private String seatsAvailable;
    private String type;

...

来自JpaTest.java

import java.util.Random;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;

import com.jared.tutoring.model.courses.Classes;

public class JpaTest {

    public void doDBStuff() {
        EntityManagerFactory factory = Persistence.createEntityManagerFactory("JPADemo");
        EntityManager manager = factory.createEntityManager();

        Classes dummyClass = createDummyCourse();

        manager.getTransaction().begin();
        try {
            manager.persist(dummyClass);
        } catch (Exception e) {
            e.printStackTrace();
        }
        manager.getTransaction().commit();

        System.out.println(".. done");
    }


    private Classes createDummyCourse() {

        Random rand = new Random();
        int randomNum = rand.nextInt(100000);

        Classes newClass = new Classes();
        newClass.setId("NewId" + randomNum);
        newClass.setName("Course Name" + randomNum);
        newClass.setDescription("Course Description" + randomNum);
        newClass.setAssociatedTerm("Assocaiated Term" + randomNum);
        newClass.setRegistrationLevels("Registration Levels" + randomNum);
        newClass.setCreditHours("Credit Hours" + randomNum);
        newClass.setInstructorName("Instructor Name" + randomNum);
        newClass.setLocation("Location" + randomNum);
        newClass.setLabInfo("Lab Info" + randomNum);
        newClass.setDays("Days");
        newClass.setTime("Time");
        newClass.setScheduleType("Schedule Type");
        newClass.setSeatsAvailable("Seats Avaliable");
        newClass.setType("Type");

        return newClass;
    }

}

只是提醒一下,这个相同的persistence.xml文件,以及插入数据库的相同代码都在另一个非网络项目中,就像一个冠军。

提前致谢!

0 个答案:

没有答案