本文介绍了在两个不同的模式中使用两个相同命名的表时,避免使用Hibernate注释异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个表,两个命名为两种不同模式的语言,可以将它们称为schema1和schema2。



当我为每个表格注释模型时,我的代码如下所示:
@Entity
@Table(name =language ,catalog =schema1)
public class语言{

  ........... .......... 

@Entity
@Table(name =language,catalog =schema2)
public class语言{

但是当这样做时,我会收到一个注释异常错误如下:



org.hibernate.AnnotationException:使用相同的实体名称两次:语言



那么这是否意味着我不能在两个不同的数据库模式或者我只是注释我的模型错误?



谢谢,



Elliott

解决方案

事实证明,模式2中的模型是一个对象,它是模式1中模型对象的扩展.Hibernate不喜欢两种表一种施工重命名相同。使第二个对象不是第一个对象的扩展,消除了问题。


I have two tables, both named Language in two different schemas, lets call them schema1 and schema2.

When I annotate the models for each of these tables, my code looks like this: @Entity @Table(name="language", catalog="schema1") public class Language {

.....................

 @Entity
 @Table(name="language", catalog="schema2")
 public class Language {

But when doing this, I get an annotation Exception error as follows:

org.hibernate.AnnotationException: Use of the same entity name twice: Language

So, does this mean I can't have identically named tables in two different database schemas or am I just annotating my models wrong?

Thank you,

Elliott

解决方案

It turns out that the model in schema 2 was an object that was an extension of the model object in schema 1. Hibernate does not like this kind of construction when the two tables are named the same. Making the second object not an extension of the first, eliminated the problem.

这篇关于在两个不同的模式中使用两个相同命名的表时,避免使用Hibernate注释异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-16 03:56