English 中文(简体)
@SequenceGenerator on category annotated with @MappedSuperlem
原标题:@SequenceGenerator on class annotated with @MappedSuperclass

我的结构如下:

@MappedSuperclass
public abstract class BaseEntity {
  @Id @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "seqGenerator")
  private Long id;
}

@MappedSuperclass
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@SequenceGenerator(name = "seqGenerator", sequenceName = "DICTIONARY_SEQ")
public abstract class Intermed extends BaseEntity {}

@Entity
public class MyEntity1 extends Intermed {}

@Entity
public class MyEntity2 extends Intermed {}

下面是例外:

    Caused by: org.springframework.beans.factory.BeanCreationException: 
Error creating bean with name  sessionFactory  defined in class path resource [context/applicationContext.xml]: 
Invocation of init method failed; nested exception is org.hibernate.AnnotationException: Unknown Id.generator: seqGenerator

When I change @MappedSuperclass to @Entity on Intermed class, everything works OK. Are there any problems with using @MappedSuperclass and @SequenceGenerator? Or I have missed something?

最佳回答

以下是JPA 1.0 光谱对SequenceGenerator的说明:

9.1.37 SequenceGenerator Annotation

The SequenceGenerator annotation defines a primary key generator that may be referenced by name when a generator element is specified for the GeneratedValue annotation. A sequence generator may be specified on the entity class or on the primary key field or property. The scope of the generator name is global to the persistence unit (across all generator types).

绘制地图的超级阶级不是实体。 因此,根据我读到的幽灵,你想要做的事情是不可能的。 要么将<代码>Intermed分类为实体,要么将<代码>SequenceGenerator上列。

问题回答

我在试图实现广泛应用的发电机的同时,也遇到了这一问题。

解决办法实际上在第一个答案中: 表示主要领域()的顺序生成者。

与此类似:

@MappedSuperclass
public abstract class BaseEntity {
  @Id
  @SequenceGenerator(name = "seqGenerator", sequenceName = "DICTIONARY_SEQ")
  @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "seqGenerator")
  private Long id;
}

@MappedSuperclass
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
public abstract class Intermed extends BaseEntity {}

@Entity
public class MyEntity1 extends Intermed {}

@Entity
public class MyEntity2 extends Intermed {}

虽然这样做似乎令人瞩目(至少对我而言),但它确实发挥了作用。





相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签