Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/383.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
HibernateJavaWeb应用程序_Java_Hibernate_Jsp_Web Applications - Fatal编程技术网

HibernateJavaWeb应用程序

HibernateJavaWeb应用程序,java,hibernate,jsp,web-applications,Java,Hibernate,Jsp,Web Applications,我正在开发一个使用hibernate框架的java JSP Web应用程序 我完全是JSP/hibernate的初学者,我似乎无法让hibernate工作。 我遵循了本教程: 一切都成功了。我将xampp与phpmyadmin一起使用,可以通过hibernate.cfg.xml文件执行HQL查询 然后,我对我用于web应用程序的数据库进行了同样的尝试。按照所有的步骤,通过所有的向导。但是我不能执行HQL查询 给出了以下错误: org.hibernate.MappingException: An

我正在开发一个使用hibernate框架的java JSP Web应用程序

我完全是JSP/hibernate的初学者,我似乎无法让hibernate工作。 我遵循了本教程: 一切都成功了。我将xampp与phpmyadmin一起使用,可以通过hibernate.cfg.xml文件执行HQL查询

然后,我对我用于web应用程序的数据库进行了同样的尝试。按照所有的步骤,通过所有的向导。但是我不能执行HQL查询

给出了以下错误:

org.hibernate.MappingException: An association from the table campingsperfestival refers to an unmapped class: festivalOverview.Campings
    at org.hibernate.cfg.Configuration.secondPassCompileForeignKeys(Configuration.java:1252)
    at org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:1170)
    at org.hibernate.cfg.AnnotationConfiguration.secondPassCompile(AnnotationConfiguration.java:324)
    at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1286)
    at org.hibernate.cfg.AnnotationConfiguration.buildSessionFactory(AnnotationConfiguration.java:859)
我遵循Hibernate映射文件和数据库向导中的POJO,它为数据库中的所有表生成了一个.java和.hbm.xml文件,只有一个表除外:“CampingPerfestival”表。我又做了几次向导并重新启动了它,但它仍然没有为“campingperfestival”表生成.java和.hbm.xml文件

“campingperfestival”表是一个具有两个id的表,这两个id都有一个外键。有些节日和露营都有ID,“campingsperfestival”与一个表中的这两个ID匹配

Campings.hbm.xml:

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!-- Generated 20-apr-2013 12:04:37 by Hibernate Tools 3.2.1.GA -->
<hibernate-mapping>
    <class name="festivalOverview.Campings" table="campings" catalog="groep11_festivals">
        <id name="campId" type="java.lang.Integer">
            <column name="camp_id" />
            <generator class="identity" />
        </id>
        <property name="campAdres" type="string">
            <column name="camp_adres" not-null="true" />
        </property>
        <property name="campCap" type="int">
            <column name="camp_cap" not-null="true" />
        </property>
        <set name="festivalses" inverse="true" table="campingsperfestival">
            <key>
                <column name="camp_id" not-null="true" />
            </key>
            <many-to-many entity-name="festivalOverview.Festivals">
                <column name="fest_id" not-null="true" />
            </many-to-many>
        </set>
        <set name="facpercamps" inverse="true">
            <key>
                <column name="camp_id" not-null="true" />
            </key>
            <one-to-many class="festivalOverview.Facpercamp" />
        </set>
    </class>
</hibernate-mapping>
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!-- Generated 20-apr-2013 12:04:37 by Hibernate Tools 3.2.1.GA -->
<hibernate-mapping>
    <class name="festivalOverview.Festivals" table="festivals" catalog="groep11_festivals">
        <id name="festId" type="java.lang.Integer">
            <column name="fest_id" />
            <generator class="identity" />
        </id>
        <property name="festNaam" type="string">
            <column name="fest_naam" length="100" not-null="true" />
        </property>
        <property name="festLocatie" type="string">
            <column name="fest_locatie" length="200" not-null="true" />
        </property>
        <property name="festDatum" type="date">
            <column name="fest_datum" length="10" not-null="true" />
        </property>
        <property name="festDuur" type="byte">
            <column name="fest_duur" not-null="true" />
        </property>
        <set name="ticketses" inverse="true">
            <key>
                <column name="fest_id" not-null="true" />
            </key>
            <one-to-many class="festivalOverview.Tickets" />
        </set>
        <set name="bandsperfestivals" inverse="true">
            <key>
                <column name="fest_id" not-null="true" />
            </key>
            <one-to-many class="festivalOverview.Bandsperfestival" />
        </set>
        <set name="campingses" inverse="false" table="campingsperfestival">
            <key>
                <column name="fest_id" not-null="true" />
            </key>
            <many-to-many entity-name="festivalOverview.Campings">
                <column name="camp_id" not-null="true" />
            </many-to-many>
        </set>
        <set name="tickettypesperfestivals" inverse="true">
            <key>
                <column name="fest_id" not-null="true" />
            </key>
            <one-to-many class="festivalOverview.Tickettypesperfestival" />
        </set>
    </class>
</hibernate-mapping>

festions.hbm.xml:

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!-- Generated 20-apr-2013 12:04:37 by Hibernate Tools 3.2.1.GA -->
<hibernate-mapping>
    <class name="festivalOverview.Campings" table="campings" catalog="groep11_festivals">
        <id name="campId" type="java.lang.Integer">
            <column name="camp_id" />
            <generator class="identity" />
        </id>
        <property name="campAdres" type="string">
            <column name="camp_adres" not-null="true" />
        </property>
        <property name="campCap" type="int">
            <column name="camp_cap" not-null="true" />
        </property>
        <set name="festivalses" inverse="true" table="campingsperfestival">
            <key>
                <column name="camp_id" not-null="true" />
            </key>
            <many-to-many entity-name="festivalOverview.Festivals">
                <column name="fest_id" not-null="true" />
            </many-to-many>
        </set>
        <set name="facpercamps" inverse="true">
            <key>
                <column name="camp_id" not-null="true" />
            </key>
            <one-to-many class="festivalOverview.Facpercamp" />
        </set>
    </class>
</hibernate-mapping>
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!-- Generated 20-apr-2013 12:04:37 by Hibernate Tools 3.2.1.GA -->
<hibernate-mapping>
    <class name="festivalOverview.Festivals" table="festivals" catalog="groep11_festivals">
        <id name="festId" type="java.lang.Integer">
            <column name="fest_id" />
            <generator class="identity" />
        </id>
        <property name="festNaam" type="string">
            <column name="fest_naam" length="100" not-null="true" />
        </property>
        <property name="festLocatie" type="string">
            <column name="fest_locatie" length="200" not-null="true" />
        </property>
        <property name="festDatum" type="date">
            <column name="fest_datum" length="10" not-null="true" />
        </property>
        <property name="festDuur" type="byte">
            <column name="fest_duur" not-null="true" />
        </property>
        <set name="ticketses" inverse="true">
            <key>
                <column name="fest_id" not-null="true" />
            </key>
            <one-to-many class="festivalOverview.Tickets" />
        </set>
        <set name="bandsperfestivals" inverse="true">
            <key>
                <column name="fest_id" not-null="true" />
            </key>
            <one-to-many class="festivalOverview.Bandsperfestival" />
        </set>
        <set name="campingses" inverse="false" table="campingsperfestival">
            <key>
                <column name="fest_id" not-null="true" />
            </key>
            <many-to-many entity-name="festivalOverview.Campings">
                <column name="camp_id" not-null="true" />
            </many-to-many>
        </set>
        <set name="tickettypesperfestivals" inverse="true">
            <key>
                <column name="fest_id" not-null="true" />
            </key>
            <one-to-many class="festivalOverview.Tickettypesperfestival" />
        </set>
    </class>
</hibernate-mapping>


我只是一个使用hibernate的初学者,真的不知道如何解决这个问题。非常感谢您的帮助

我假设campingperfestival是Campings和Festival两个类之间的联接表?您是否定义了这两个类及其映射

您遇到的错误是,它无法创建campingperfestival,因为它引用的是未定义为hibernate类的Campings。因此,请确保已定义露营,并且映射正确

如果您还不清楚,如果您展示露营和节日的java/映射,我们可以提供更多帮助


另外,如果这是一个新项目,我真的建议您使用基于注释的hibernate类。您可能会发现自己创建hibernate实体类比使用NetBeasn更有效,但这取决于个人喜好。

所以我需要自己为campingsperfestival创建.java和.hbm.xml?为什么向导不这样做?我没有使用向导,您是否从表中反向工程映射?向导是否为露营和节日表创建了java和映射?是的,我是。向导已为camping表和Festival表创建了java和映射,但尚未为campingsperfestival表创建映射OK,因此您是否可以检查在连接表上正确设置了两个表的fks?还有,它可能是向导中的命令吗?向导正在尝试在处理营地之前生成联接表吗?CampingPerfestival有两个属性:fest_id和camp_id。fest_id有外键Festival。fest_id和camp_id有外键campings.camp_id,所以应该是正确的。该向导非常简单,您无法选择映射哪些类,通常所有表都被映射,但在我的例子中,campingperfestival没有被映射。