2つのテーブルをマッピングできない休止状態
-
21-09-2019 - |
質問
私はそれが可能であるかを理解したいと思います: 私は1つのテーブルで働いていたまではすべてが、罰金を働きました 私は別のテーブルにマップされている場合は、以下に示すように、失敗します:
Glassfishの開始
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)
...
設定
TABLE1
<!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>
table2の
<!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で、クエリがする必要がありますので、「Impiantoから...」ない「IMPIANTIからは...」 - クラス名ではなく、テーブル名から選択します。
。所属していません StackOverflow