Inheritage mapping error Eclipse

Hello, I’m doing a proyect for college using Hibernate and Eclipse. I have a superclass and a subclass. The subclass are also conect whit a diferent class. When I try to conect the subclass I get this error: Could not get constructor for org.hibernate.persister.entity.UnionSubclassEntityPersister . When I erase the one-to-one relation of the subclass the program run correctly. How can this be solve?

Superclass:

package datos;
public abstract class Tarifa {
	private long idValorTarifa;
	private double valorViaje;
	
	public Tarifa() {}
	
	public Tarifa(double valorViaje) {
		this.valorViaje = valorViaje;
	}	

	public long getIdValorTarifa() {
		return idValorTarifa;
	}

	public void setIdValorTarifa(long idValorTarifa) {
		this.idValorTarifa = idValorTarifa;
	}

	public double getValorViaje() {
		return valorViaje;
	}

	public void setValorViaje(double valorViaje) {
		this.valorViaje = valorViaje;
	}

	@Override
	public String toString() {
		return "Tarifa: $" + valorViaje;
	}
	
}

Subclass:

package datos;
public class TarifaColectivo extends Tarifa {

	private SeccionColectivo seccion;
	
	
	public TarifaColectivo() {	}
	
	public TarifaColectivo(double valorViaje, SeccionColectivo seccion) {
		super(valorViaje);
		this.seccion = seccion;
	}

	public SeccionColectivo getSeccion() {
		return seccion;
	}
	public void setSeccion(SeccionColectivo seccion) {
		this.seccion = seccion;
	}

}

The other Class:

package datos;

public class SeccionColectivo {
	private long seccion;
	private double valorNormal;
	private double valorTarifaSocial;
	private TarifaColectivo tarifaColectivo;
	
	public SeccionColectivo() {}
	
	public SeccionColectivo(long seccion, double valorNormal, double valorTarifaSocial) {
		this.seccion = seccion;
		this.valorNormal = valorNormal;
		this.valorTarifaSocial = valorTarifaSocial;
	}


	public long getSeccion() {
		return seccion;
	}
	public void setSeccion(long seccion) {
		this.seccion = seccion;
	}
	public double getValorNormal() {
		return valorNormal;
	}
	public void setValorNormal(double valorNormal) {
		this.valorNormal = valorNormal;
	}
	public double getValorTarifaSocial() {
		return valorTarifaSocial;
	}
	public void setValorTarifaSocial(double valorTarifaSocial) {
		this.valorTarifaSocial = valorTarifaSocial;
	}
	public TarifaColectivo getTarifaColectivo() {
		return tarifaColectivo;
	}

	public void setTarifaColectivo(TarifaColectivo tarifaColectivo) {
		this.tarifaColectivo = tarifaColectivo;
	}

	@Override
	public String toString() {
		return "SeccionColectivo [seccion=" + seccion + ", valorNormal=" + valorNormal + ", valorTarifaSocial="
				+ valorTarifaSocial + "]";
	}
	
	
}

Mapping of the Superclass:

<?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>
	<class name="datos.Tarifa" abstract="true">
		<id name="idValorTarifa" column="idtarifa" >
			<generator class="increment"/>
		</id>
		<property name = "valorViaje" column="valor_tarifa" type="double"/>
    </class>
</hibernate-mapping>

Mapping of the Subclass:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC 
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
    <union-subclass name="datos.TarifaColectivo" table="tarifa_colectivo" extends="datos.Tarifa">
    <one-to-one name="seccion_colectivo" class="datos.SeccionColectivo"/>
    </union-subclass>
</hibernate-mapping>

Mapping of the other Class:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
	<class name="datos.SeccionColectivo" table="seccion_colectivo">
		<id column="seccion" name="seccion">
			<generator class="assigned"/>	
		</id>
	<property column="valor_tarifa_normal" name="valorNormal" type="double"/>
	<property column="valor_tarifa_social" name="valorTarifaSocial" type="double"/>
	<one-to-one name="tarifa_colectivo" class="datos.TarifaColectivo"/>
	</class>
</hibernate-mapping>

Thanks for the help.

HBM mappings are considered deprecated by now. Try with annotations since they are better supported.

Meanwhile, you can also open a Jira issue as it sounds like a bug.

Thanks for the answer. Unfortunately the professor want us to use hbm.

Try to replicate it with this test case template:

http://in.relation.to/2016/01/14/hibernate-jpa-test-case-template/

I have already done it, what do I do with the Failure Trace?. I’m sorry but I’m new with this.
Thank you.

Try to upload the replicating test case and share the link here so we can take a look on it.

This is all the Failure Trace

javax.persistence.PersistenceException: [PersistenceUnit: templatePU] Unable to build Hibernate SessionFactory
	at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.persistenceException(EntityManagerFactoryBuilderImpl.java:1249)
	at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.access$600(EntityManagerFactoryBuilderImpl.java:120)
	at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl$4.perform(EntityManagerFactoryBuilderImpl.java:860)
	at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl$4.perform(EntityManagerFactoryBuilderImpl.java:850)
	at org.hibernate.boot.registry.classloading.internal.ClassLoaderServiceImpl.withTccl(ClassLoaderServiceImpl.java:425)
	at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:849)
	at org.hibernate.jpa.HibernatePersistenceProvider.createEntityManagerFactory(HibernatePersistenceProvider.java:75)
	at org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:54)
	at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:55)
	at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:39)
	at org.hibernate.bugs.JPAUnitTestCase.init(JPAUnitTestCase.java:20)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)
	at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
	at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)
	at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:24)
	at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)
	at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
	at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
	at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
	at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
	at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
	at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
	at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
	at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86)
	at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:538)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:760)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:460)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:206)
Caused by: org.hibernate.MappingException: Could not get constructor for org.hibernate.persister.entity.UnionSubclassEntityPersister
	at org.hibernate.persister.internal.PersisterFactoryImpl.create(PersisterFactoryImpl.java:185)
	at org.hibernate.persister.internal.PersisterFactoryImpl.createEntityPersister(PersisterFactoryImpl.java:135)
	at org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:401)
	at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1859)
	at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl$4.perform(EntityManagerFactoryBuilderImpl.java:857)
	... 32 more
Caused by: org.hibernate.HibernateException: Unable to instantiate default tuplizer [org.hibernate.tuple.entity.PojoEntityTuplizer]
	at org.hibernate.tuple.entity.EntityTuplizerFactory.constructTuplizer(EntityTuplizerFactory.java:138)
	at org.hibernate.tuple.entity.EntityTuplizerFactory.constructDefaultTuplizer(EntityTuplizerFactory.java:188)
	at org.hibernate.tuple.entity.EntityMetamodel.<init>(EntityMetamodel.java:403)
	at org.hibernate.persister.entity.AbstractEntityPersister.<init>(AbstractEntityPersister.java:520)
	at org.hibernate.persister.entity.UnionSubclassEntityPersister.<init>(UnionSubclassEntityPersister.java:93)
	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
	at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
	at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
	at org.hibernate.persister.internal.PersisterFactoryImpl.create(PersisterFactoryImpl.java:163)
	... 36 more
Caused by: java.lang.reflect.InvocationTargetException
	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
	at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
	at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
	at org.hibernate.tuple.entity.EntityTuplizerFactory.constructTuplizer(EntityTuplizerFactory.java:135)
	... 45 more
Caused by: org.hibernate.PropertyNotFoundException: Could not find a getter for seccion_colectivo in class datos.TarifaColectivo
	at org.hibernate.property.BasicPropertyAccessor.createGetter(BasicPropertyAccessor.java:310)
	at org.hibernate.property.BasicPropertyAccessor.getGetter(BasicPropertyAccessor.java:304)
	at org.hibernate.mapping.Property.getGetter(Property.java:323)
	at org.hibernate.tuple.entity.PojoEntityTuplizer.buildPropertyGetter(PojoEntityTuplizer.java:411)
	at org.hibernate.tuple.entity.AbstractEntityTuplizer.<init>(AbstractEntityTuplizer.java:200)
	at org.hibernate.tuple.entity.PojoEntityTuplizer.<init>(PojoEntityTuplizer.java:80)
	... 50 more

java.lang.NullPointerException
	at org.hibernate.bugs.JPAUnitTestCase.destroy(JPAUnitTestCase.java:25)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)
	at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
	at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)
	at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:33)
	at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
	at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
	at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
	at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
	at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
	at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
	at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
	at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86)
	at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:538)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:760)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:460)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:206)


The exception tells exactly what you have to do.

org.hibernate.PropertyNotFoundException: Could not find a getter for seccion_colectivo in class datos.TarifaColectivo

Yes, but i have that getter. In the code that I posted shows the getter and setter. And I dont have a variable call seccion_colectivo

If you generated the DB schema manually, it might not be what Hibernate expects. Try comparing yours with the one generated by hbm2ddl=auto.