[hibernate-issues] [Hibernate-JIRA] Commented: (HBX-1193) reverse engineering of UniqueConstraint annotation for function-based indexes

Steve Maring (JIRA) noreply at atlassian.com
Thu Oct 13 10:16:19 EDT 2011


    [ http://opensource.atlassian.com/projects/hibernate/browse/HBX-1193?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=44034#comment-44034 ] 

Steve Maring commented on HBX-1193:
-----------------------------------

Looking at org.hibernate.cfg.reveng.dialect.JDBCMetaDataDialect in the getIndexInfo method, it seems to return a ResultSetIterator with a map that contains the "TYPE" of the index.  In this case, that would contain "FUNCTION-BASED NORMAL" instead of just "NORMAL".

generateAnnTableUniqueConstraint in org.hibernate.tool.hbm2x.pojo.EntityPOJOClass seems to accept a org.hibernate.mapping.Table from which it asks to getUniqueKeyIterator, wherein it then generates the UniqueConstraint annotations.

nothing all that special happens in org.hibernate.mapping.Table as far as uniqueKeys are concerned

I think the fix may be whereever the ResultSetIterator from JDBCMetaDataDialect is used to set the uniqueKeys in the Table instance.  Perhaps, at that point, a check could be made to ensure that the TYPE does not contain "FUNCTION-BASED"

not found where that is just yet

> reverse engineering of UniqueConstraint annotation for function-based indexes
> -----------------------------------------------------------------------------
>
>                 Key: HBX-1193
>                 URL: http://opensource.atlassian.com/projects/hibernate/browse/HBX-1193
>             Project: Hibernate Tools
>          Issue Type: Bug
>          Components: hbm2java
>    Affects Versions: 3.2.4.GA
>            Reporter: Steve Maring
>              Labels: engineering, function-based, hbm2java, index, reverse, uniqueconstraint
>
> getting a runtime error ...
> [code]org.hibernate.AnnotationException: Unable to create unique key constraint (SYS_NC00048$) on table WRKR: SYS_NC00048$ not found[/code]
> the generated entity looks like this:
> [code]@Entity
> @Table(name="WRKR"
>     , uniqueConstraints = {  @UniqueConstraint(columnNames="SYS_NC00048$"),
>                                 @UniqueConstraint(columnNames="SYS_NC00047$"), 
>                                 @UniqueConstraint(columnNames="LOGIN_VAL"), 
>                                 @UniqueConstraint(columnNames="SOCL_SECUR_NUM_VAL"), 
>                                 @UniqueConstraint(columnNames="AD_LOGIN_VAL")} 
> )
> public class Wrkr  implements java.io.Serializable {[/code]
> Interesting thing is that this data seems to be coming from the table Indexes.  They read ...
> [code]
> Index Name		        Uniqueness	        Index Type		         Columns     	Column Expression
> IX_WRKR_01		        UNIQUE		NORMAL			        WRKR_SEQ	
> IX_WRKR_12		        UNIQUE		NORMAL			        SOCL_SECUR_NUM_VAL	
> IX_WRKR_16		        UNIQUE		FUNCTION-BASED NORMAL	SYS_NC00047$		UPPER("AD_LOGIN_VAL")
> IX_WRKR_17		        UNIQUE		FUNCTION-BASED NORMAL	SYS_NC00048$		UPPER("LOGIN_VAL")
> IX_WRKR_UQ_LOGIN_VAL	  UNIQUE		NORMAL			        LOGIN_VAL	
> IX_WRKR_UQ_AD_LOGIN_VAL	UNIQUE		NORMAL			        AD_LOGIN_VAL
> [/code]
> WRKR_SEQ is the primary key, and SOCL_SECUR_NUM_VAL, LOGIN_VAL, and AD_LOGIN_VAL are "real" columns.  The other two SYS_NC0004#$ are not actual columns in the table.  They seem to be some sort of "function-based" Oracle indexes/columns that you only see in the list of indexes.
> tried:
> <table name="WRKR">
> 		<column name="SYS_NC00047$" exclude="true"/>
> 		<column name="SYS_NC00048$" exclude="true"/>
> </table>
> but it didn't help.
> The problem seems to be isolated to the annotation generation.  I would venture to say that it should NOT be generating @UniqueConstraint entries for columns that don't actually exist in the table.

--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira

        


More information about the hibernate-issues mailing list