[英]Spring Data Repository JPA Entity Inheritance Issue: Cannot instantiate abstract class or interface
I'm using the below web app stack and when I run my TestNG test and the container gets initialized my test class fails to autowire the ExampleRepository with the below exception. 我正在使用下面的Web应用程序堆栈,当我运行TestNG测试并且初始化容器时,我的测试类无法自动连接ExampleRepository并带有以下异常。 Any ideas on how to map such a relationship?
关于如何映射这种关系有什么想法? When I start a jetty web server with the same web application I don't get any startup exceptions, so it could be an issue with AbstractTransactionalTestNGSpringContextTests.
当我使用相同的Web应用程序启动Jetty Web服务器时,没有任何启动异常,因此AbstractTransactionalTestNGSpringContextTests可能是一个问题。
Stack: 堆:
Spring - 3.2.2.RELEASE
Spring Data - 1.3.0.RELEASE
Hibernate - 3.6.10.Final
TestNG - 6.1.1
Exception: 例外:
Cannot instantiate abstract class or interface: com.test.Example; nested exception is org.hibernate.InstantiationException
JPA Entities: JPA实体:
@Entity
@Table(name = "EXAMPLE")
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(name = "type", discriminatorType = DiscriminatorType.STRING)
public abstract class Example {}
@Entity
@DiscriminatorValue("examplea")
public class ExampleA extends Example {}
@Entity
@DiscriminatorValue("exampleb")
public class ExampleB extends Example {}
Repository: 库:
public interface ExampleRepository extends JpaRepository<Example, Long> {}
TestNG Class: TestNG类:
public class ExampleTest extends AbstractTransactionalTestNGSpringContextTests{
@Autowired
private ExampleRepository exampleRepository;
}
Make Example class as Interface and let other classes implement it. 将Example类作为Interface并让其他类实现它。 As exception clearly says you cannot instantiate an abstract class.
异常明确表明您无法实例化抽象类。 Making Example class as interface you can instantiate its types ie the classes implementing it.
将Example类作为接口,您可以实例化其类型,即实现它的类。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.