Versions:
Hibernate Core 3.2.5.GA
Hibernate Annotations 3.3.0.GA
Name and version of the database you are using:
Oracle 9i/10g
We are using Hibernate Core/Annotations targeting Oracle 9i/10g as underlying database.
As you probably know, Oracle has limitation that identifier name cannot be longer than 30 characters.
According to that we have developed our own naming strategy (extended from EJB3NamingStrategy) that truncates
all identifier names to 30 characters (we are taking care of identifiers starting with same character sequences) as following:
Code:
public class OracleEJB3NamingStrategy extends EJB3NamingStrategy {
private static final int maxNameLength = 30;
private static final int subNameLength = 24;
private static final String nameTemplate = "%1$s_%2$05d";
private int counter = 0;
private Map<String, String> names = new HashMap<String, String>();
public String classToTableName(String className) {
return tableName(super.classToTableName(className));
}
public String propertyToColumnName(String propertyName) {
return columnName(super.propertyToColumnName(propertyName));
}
public String tableName(String tableName) {
return getRealName(tableName);
}
public String columnName(String columnName) {
return getRealName(columnName);
}
private String getRealName(String logicalName) {
if (!names.keySet().contains(logicalName)) {
if (logicalName.length() <= maxNameLength) {
names.put(logicalName, logicalName);
} else {
String realName = String.format(nameTemplate, logicalName.substring(0, subNameLength), counter++);
names.put(logicalName, realName);
}
}
return names.get(logicalName);
}
}
On the other side, we have an optional one-to-many/many-to-one association between two entities which is modeled like this:
Code:
@Entity
public class Person {
@OneToMany(mappedBy = "person")
private Set<Address> addresses = new HashSet<Address>();
}
and
Code:
@Entity
public class Address implements java.io.Serializable {
@ManyToOne
@JoinTable(name = "personAddress_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")
private Person person;
}
Name of the Join Table is intentionally such long and is given as an example - in reality it is generated by our code generator and therfore its name is out of our control.
Problem we are facing during generating database schema is following:
Code:
[main] 23:07:40,125 ERROR AbstractKernelController:440 - Error installing to Start: name=persistence.units:unitName=codegen state=Create
org.hibernate.AnnotationException: Cannot find the expected secondary table: no personAddress_aaaaaaaaaa_00000 available for pckg1.Address
at org.hibernate.cfg.Ejb3Column.getJoin(Ejb3Column.java:293)
at org.hibernate.cfg.Ejb3Column.getTable(Ejb3Column.java:272)
at org.hibernate.cfg.AnnotationBinder.bindManyToOne(AnnotationBinder.java:1833)
at org.hibernate.cfg.AnnotationBinder.processElementAnnotations(AnnotationBinder.java:1311)
at org.hibernate.cfg.AnnotationBinder.bindClass(AnnotationBinder.java:733)
at org.hibernate.cfg.AnnotationConfiguration.processArtifactsOfType(AnnotationConfiguration.java:498)
at org.hibernate.cfg.AnnotationConfiguration.secondPassCompile(AnnotationConfiguration.java:277)
at org.hibernate.cfg.Configuration.buildMappings(Configuration.java:1115)
at org.hibernate.ejb.Ejb3Configuration.buildMappings(Ejb3Configuration.java:1269)
at org.hibernate.ejb.EventListenerConfigurator.configure(EventListenerConfigurator.java:150)
at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:888)
at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:416)
at org.hibernate.ejb.HibernatePersistence.createContainerEntityManagerFactory(HibernatePersistence.java:126)
at org.jboss.ejb3.entity.PersistenceUnitDeployment.start(PersistenceUnitDeployment.java:264)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.jboss.reflect.plugins.introspection.ReflectionUtils.invoke(ReflectionUtils.java:55)
at org.jboss.reflect.plugins.introspection.ReflectMethodInfoImpl.invoke(ReflectMethodInfoImpl.java:107)
at org.jboss.joinpoint.plugins.BasicMethodJoinPoint.dispatch(BasicMethodJoinPoint.java:66)
at org.jboss.kernel.plugins.dependency.KernelControllerContextAction.dispatchJoinPoint(KernelControllerContextAction.java:75)
at org.jboss.kernel.plugins.dependency.LifecycleAction.installAction(LifecycleAction.java:115)
at org.jboss.kernel.plugins.dependency.KernelControllerContextAction.install(KernelControllerContextAction.java:100)
at org.jboss.dependency.plugins.AbstractControllerContextActions.install(AbstractControllerContextActions.java:51)
at org.jboss.dependency.plugins.AbstractControllerContext.install(AbstractControllerContext.java:226)
at org.jboss.dependency.plugins.AbstractController.install(AbstractController.java:709)
at org.jboss.dependency.plugins.AbstractController.incrementState(AbstractController.java:429)
at org.jboss.dependency.plugins.AbstractController.resolveContexts(AbstractController.java:538)
at org.jboss.dependency.plugins.AbstractController.resolveContexts(AbstractController.java:472)
at org.jboss.dependency.plugins.AbstractController.install(AbstractController.java:274)
at org.jboss.dependency.plugins.AbstractController.install(AbstractController.java:177)
at org.jboss.kernel.plugins.dependency.AbstractKernelController.install(AbstractKernelController.java:79)
at org.jboss.kernel.plugins.dependency.AbstractKernelController.install(AbstractKernelController.java:73)
at org.jboss.ejb3.MCKernelAbstraction.install(MCKernelAbstraction.java:131)
at org.jboss.ejb3.Ejb3Deployment.startPersistenceUnits(Ejb3Deployment.java:467)
at org.jboss.ejb3.Ejb3Deployment.start(Ejb3Deployment.java:317)
at org.jboss.ejb3.embedded.EJB3StandaloneDeployer.start(EJB3StandaloneDeployer.java:478)
at org.jboss.ejb3.embedded.EJB3StandaloneBootstrap.scanClasspath(EJB3StandaloneBootstrap.java:235)
at CodeGen.main(CodeGen.java:11)
It smells like bug in the Hibernate Annotations implementation for us but we want somebody to confirm it.
Or maybe there is some workaround :)?