Hibernate Annotation for Entity existing in more than 1 catalog

后端 未结 3 1924
死守一世寂寞
死守一世寂寞 2021-02-06 08:13

I have a Person entity mapped by Hibernate to a database table in a database catalog \"Active\". After a period of time, records in this database table in the \"Active\" catalo

3条回答
  •  爱一瞬间的悲伤
    2021-02-06 08:59

    My thought would be to write a query to select both tables from db A and B. then create a query with hibernate and map it to your class.

    example:

    @Entity
    @NamedNativeQuery(
    name="GetAllPerson",
    query="select * from A.Person inner join B.Person on A.Person.Id = B.Person.Id"
    )
    public class Person  {
    ...
    }
    

    Not sure if it could work, your question made me also curious about the best way to do it :). I'll test it tonight after work and see if its any good.

提交回复
热议问题