gpt4 book ai didi

java - hibernate 映射两个表失败

转载 作者:行者123 更新时间:2023-11-30 05:13:28 24 4
gpt4 key购买 nike

我想了解这是怎么可能的:在我使用一张 table 之前一切都工作正常,当我映射另一个表时,它失败,如下所示:

玻璃鱼开始

INFO: configuring from resource: /hibernate.cfg.xml
INFO: Configuration resource: /hibernate.cfg.xml
INFO: Reading mappings from resource : hibernate_centrale.hbm.xml //first table
INFO: Mapping class: com.italtel.patchfinder.objects.centrale -> centrale
INFO: Reading mappings from resource : hibernate_impianti.hbm.xml //second table
INFO: Mapping class: com.italtel.patchfinder.objects.Impianto -> impianti
INFO: Configured SessionFactory: null


INFO: schema update complete
INFO: Hibernate: select centrale0_.id as id0_, centrale0_.name as name0_, centrale0_.impianto as impianto0_, centrale0_.servizio as servizio0_ from centrale centrale0_ group by centrale0_.name
INFO: Hibernate: select centrale0_.id as id0_, centrale0_.name as name0_, centrale0_.impianto as impianto0_, centrale0_.servizio as servizio0_ from centrale centrale0_ where centrale0_.name='ANCONA' order by centrale0_.name asc

//Error
org.hibernate.hql.ast.QuerySyntaxException: impianti is not mapped [from impianti where impianto='SD' order by modulo asc]
at org.hibernate.hql.ast.util.SessionFactoryHelper.requireClassPersister(SessionFactoryHelper.java:181)
...

配置

表1

<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD
3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"> <hibernate-mapping>
<class name="com.italtel.patchfinder.objects.Impianto" table="impianti">
<id column="id" name="id">
<generator class="increment"/>
</id>
<property name="impianto"/>
<property name="modulo"/>
</class> </hibernate-mapping>

表2

<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="com.italtel.patchfinder.objects.centrale" table="centrale">
<id column="id" name="id">
<generator class="increment"/>
</id>
<property name="name"/>
<property name="impianto"/>
<property name="servizio"/>
</class>
</hibernate-mapping>

连接的东西...

    <property name="hbm2ddl.auto">update</property>
<mapping resource="hibernate_centrale.hbm.xml"/>
<mapping resource="hibernate_impianti.hbm.xml"/>
</session-factory>
</hibernate-configuration>

`

    public List<centrale> loadAll() {
Session session = sessionFactory.getCurrentSession();
session.beginTransaction();
return session.createQuery("from centrale group by name").list();
}

public List<centrale> loadImplants(String centrale) {
Session session = sessionFactory.getCurrentSession();
session.beginTransaction();
return session.createQuery("from centrale where name='" + centrale + "' order by name asc").list();
}

public List<Impianto> loadModules(String implant) {
Session session = sessionFactory.getCurrentSession();
session.beginTransaction();
return session.createQuery("from impianti where impianto='" + implant + "' order by modulo asc").list();
}
}

你有什么建议吗?

最佳答案

根据您的映射,您的类名称是 Impianto,因此您的查询应该是“from Impianto...”而不是“from impianti...” - 从类名称中选择,而不是表名称。

关于java - hibernate 映射两个表失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2501377/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com