English 中文(简体)
在冬眠中加入两个无关的表格
原标题:Joining two unrelated tables in hibernate

我们是否有任何办法可以加入两桌,而不必在两桌之间建立直接关系,而是在休眠中有两个共同的领域?

我有两张桌子叫做锅炉板和剖面图,两张桌子之间没有直接关系,但有一个共同的域名为合同号。

I wrote the query "from Boiler_Plates bp inner join Profiles p on bp.bt_contracts=p.contract_id" but it keeps on throwing the error. " unexpected token: on near line 1, column 75 [from com.catapult.bid.model.Boiler_Plates as bp inner join Profiles as p on bp.bt_contracts=p.contract_id where bp.bt_contracts=1]".

以下是锅炉板和剖面图的冬眠绘图文件。

锅炉板绘图文件 。

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping SYSTEM "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">


<hibernate-mapping package="com.catapult.bid.model"  default-access="field" >
    <class name="Boiler_Plates" table="bt_boiler_plates" schema="bidtool">

        <id name="boiler_plate_id" type="int" column="boiler_plate_id">           
            <generator class="sequence">
                 <param name="sequence">bidtool.boiler_plates_boiler_plate_id_seq</param>
            </generator>
        </id>  

        <property name="boilerPlateName" type="string">
            <column name="boiler_plate_name" length="20" not-null="true" />
        </property>
        <property name="editable" type="int">
            <column name="editable"/>
        </property>
        <property name="boilerPlateContent" type="string">
            <column name="boiler_plate_content" length="20" />
        </property>
        <property name="insertTime" type="date" insert="false">
            <column name="insert_time_stamp"/>
        </property>
         <many-to-one class="Contracts" fetch="select" name="bt_contracts">
             <column name="contract_id"/>
        </many-to-one>
    </class> 
</hibernate-mapping>  

配置文件的映射文件

  <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping default-access="field" package="com.catapult.bid.model">
  <class name="Profiles" schema="bidtool" table="bid_tool_profiles">
    <id column="profile_id" name="profileId" type="string">
      <generator class="com.catapult.bid.commons.ProfileIDGenerator"/>
    </id>
    <many-to-one class="User" fetch="select" name="appUsers">
      <column name="user_id"/>
    </many-to-one>
    <property name="profileContent" type="string">
      <column name="profile_content"/>
    </property>
    <property name="scac" type="string">
      <column length="20" name="scac"/>
    </property>
    <property name="created" type="timestamp" update="false">
      <column name="insert_timestamp"/>
    </property>
    <property name="status" type="string">
      <column length="9" name="status" not-null="true"/>
    </property>
    <property name="editable" type="string">
      <column length="1" name="editable" not-null="true"/>
    </property>
  </class>
</hibernate-mapping>
最佳回答

在这种情况下,你唯一能做的就是 做一个内部连结 通过条款:

select a from A a, B b where a.someColumn = b.someOtherColumn and ...

只有利用总部单位之间的联系,才能适当加入。

问题回答

您需要懒惰地获取 Boiler_ Plates (您的班级不应在名称上加下划线) 和合同配置文件 。 然后使用类似 :

select bp.contracts.profiles from Boiler_Plates bp where bp.boiler_plate_id=?

您重新代码使用太多的下划线, 您也应该查看 java 编码公约 : < a href="http://www. oracle. com/technetwork/java/codeconv- 138413. html" rel=“ nofollow” >http://www. oracle. com/technetwork/java/codeconv- 138413. html/a>。





相关问题
Multiple Hibernate instances using C3P0

I am facing a weird problem and it seems to be c3p0 related. I am starting two instances of an app in the same java vm which interact with each other. After some operations "APPARENT DEADLOCK" ...

Hibernate vs Ibatis caching

We can speed up a hibernate app easyly with 2nd level cache using infinispan or ehcache/terracotta,... but ibatis only have a simple interface to implement for caching. And hibernate knows more ...

Using annotations to implement a static join in hibernate

I m relatively new to hibernate and was wondering if someone could help me out. While I have no issues implementing a normal join on multiple columns in hibernate using the @JoinColumns tag, I m ...

Hibernate query with fetch question

I have a 2 entities in a One-To-Many relationship: OfficeView.java: public class OfficeView implements java.io.Serializable { private Integer officeId; private String addr1; private ...

hibernate interceptors : afterTransactionCompletion

I wrote a Hibernate interceptor : public class MyInterceptor extends EmptyInterceptor { private boolean isCanal=false; public boolean onSave(Object entity, Serializable arg1, Object[] arg2, String[]...

How to prevent JPA from rolling back transaction?

Methods invoked: 1. Struts Action 2. Service class method (annotated by @Transactional) 3. Xfire webservice call Everything including struts (DelegatingActionProxy) and transactions is configured ...

Hibernate/GORM: collection was not processed by flush()

I have an integration test in my Grails application that fails when I try to save an entity of type Member invitingMember.save(flush: true) This raises the following exception org.hibernate....

Hibernate Criteria API equivalent for "elements()"

Is it possible to implement the following query using Criteria API? select order from ORDER as order,ITEM as item where item.itemID like ITM_01 and item in elements(order.items)

热门标签