I need to do this same thing with a table I'm working on, so I'd like to know this one, too. I tried to figure it out from the docs and noticed that a <property> can have multiple columns, so I was going to do something like this:
Code:
<property
name="column1"
column="column1"
not-null="true"
type="java.lang.Long"
/>
<property
name="column2"
column="column2"
not-null="true"
type="java.lang.Long"
/>
<property
name="uniqueconstraint"
type="java.lang.Long[]"
unique="true"
insert="false"
update="false"
>
<column name="column1"/>
<column name="column2"/>
</property>
But Hibernate complains about the type="java.lang.Long[]" (maybe a custom type is necessary??):
Quote:
[hibernatetool] org.hibernate.MappingException: Could not determine type for: java.lang.Integer[], for columns: [org.hibernate.mapping.Column(objid), org.hibernate.mapping.Column(studid)]
[hibernatetool] at org.hibernate.mapping.SimpleValue.getType(SimpleValue.java:265)
[hibernatetool] at org.hibernate.tool.hbm2x.Cfg2JavaTool.getRawTypeName(Cfg2JavaTool.java:568)
[hibernatetool] at org.hibernate.tool.hbm2x.Cfg2JavaTool.getJavaTypeName(Cfg2JavaTool.java:470)
[hibernatetool] at sun.reflect.GeneratedMethodAccessor4.invoke(Unknown Source)
[hibernatetool] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
[hibernatetool] at java.lang.reflect.Method.invoke(Method.java:324)
[hibernatetool] at org.apache.velocity.util.introspection.UberspectImpl$VelMethodImpl.invoke(UberspectImpl.java:267)
[hibernatetool] at org.apache.velocity.runtime.parser.node.ASTMethod.execute(ASTMethod.java:197)
[hibernatetool] at org.apache.velocity.runtime.parser.node.ASTReference.execute(ASTReference.java:175)
[hibernatetool] at org.apache.velocity.runtime.parser.node.ASTReference.value(ASTReference.java:327)
[hibernatetool] at org.apache.velocity.runtime.parser.node.ASTMethod.execute(ASTMethod.java:128)
[hibernatetool] at org.apache.velocity.runtime.parser.node.ASTReference.execute(ASTReference.java:175)
[hibernatetool] at org.apache.velocity.runtime.parser.node.ASTReference.render(ASTReference.java:220)
[hibernatetool] at org.apache.velocity.runtime.parser.node.ASTBlock.render(ASTBlock.java:55)
[hibernatetool] at org.apache.velocity.runtime.directive.Foreach.render(Foreach.java:166)
[hibernatetool] at org.apache.velocity.runtime.parser.node.ASTDirective.render(ASTDirective.java:114)
[hibernatetool] at org.apache.velocity.runtime.parser.node.ASTBlock.render(ASTBlock.java:55)
[hibernatetool] at org.apache.velocity.runtime.parser.node.ASTIfStatement.render(ASTIfStatement.java:70)
[hibernatetool] at org.apache.velocity.runtime.parser.node.SimpleNode.render(SimpleNode.java:230)
[hibernatetool] at org.apache.velocity.Template.merge(Template.java:256)
[hibernatetool] at org.apache.velocity.app.VelocityEngine.mergeTemplate(VelocityEngine.java:450)
[hibernatetool] at org.apache.velocity.app.VelocityEngine.mergeTemplate(VelocityEngine.java:419)
[hibernatetool] at org.hibernate.tool.hbm2x.TemplateHelper.processTemplate(TemplateHelper.java:76)
[hibernatetool] at org.hibernate.tool.hbm2x.POJOExporter.runVelocity(POJOExporter.java:91)
[hibernatetool] at org.hibernate.tool.hbm2x.POJOExporter.startPersistentClass(POJOExporter.java:62)
[hibernatetool] at org.hibernate.tool.hbm2x.ConfigurationNavigator.export(ConfigurationNavigator.java:38)
[hibernatetool] at org.hibernate.tool.ant.Hbm2JavaGeneratorTask.execute(Hbm2JavaGeneratorTask.java:42)
[hibernatetool] at org.hibernate.tool.ant.HibernateToolTask.execute(HibernateToolTask.java:121)
[hibernatetool] at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:275)
[hibernatetool] at org.apache.tools.ant.Task.perform(Task.java:364)
[hibernatetool] at org.apache.tools.ant.Target.execute(Target.java:341)
[hibernatetool] at org.apache.tools.ant.Target.performTasks(Target.java:369)
[hibernatetool] at org.apache.tools.ant.Project.executeTarget(Project.java:1214)
[hibernatetool] at org.apache.tools.ant.Project.executeTargets(Project.java:1062)
[hibernatetool] at org.eclipse.ant.internal.ui.antsupport.InternalAntRunner.run(InternalAntRunner.java:403)
[hibernatetool] at org.eclipse.ant.internal.ui.antsupport.InternalAntRunner.main(InternalAntRunner.java:139)
[hibernatetool] WARN getRawTypeName, Could not resolve type without exception for org.hibernate.mapping.Property(constraint1) Value: org.hibernate.mapping.SimpleValue([org.hibernate.mapping.Column(objid), org.hibernate.mapping.Column(studid)]) Type: null. Falling back to typename: java.lang.Integer[]
Is it possible to specify a multi-column unique constraint through the mapping files? And can SchemaExport handle this case?