-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: problem converting to annotations
PostPosted: Fri Dec 07, 2007 11:48 am 
Newbie

Joined: Thu Apr 08, 2004 8:46 am
Posts: 11
Location: Istanbul
Hi,
I am trying to convert from hbm.xml files to annotations because of some problem with Seam 2.
I have two abstract classes, "Item" and "Value" associated with a one to many unidirectional relationship. I had it working with hbm.xml files but now I cannot seem to express it with annotations.

Hibernate version:
The one delivered with seam 2.0.0GA

Mapping documents:
my older mapping for Item is
Code:
<hibernate-mapping package="datassist.payroll.entity">
   
    <class name="Item" abstract="true" >
        <id name="id" unsaved-value="-1"><generator class="native"/></id>
        <property name="name"/>
        <property name="description"/>
       
        <list name="values"  cascade="all, delete-orphan">
            <key column="item" />
            <list-index column="sortOrder"/>
            <one-to-many class="datassist.payroll.entity.value.Value"/>
        </list>
       
        <union-subclass name="Category">
            <property name="type"/>
            <many-to-one name="parentCategory" class="Category"/>
           
            <list name="childCategories">
                <key column="parentCategory"/>
                <list-index column="sortOrder"/>
                <one-to-many class="Category"/>
            </list>
           
            <list name="variables"  cascade="all, delete-orphan" >
                <key column="category"/>
                <list-index column="sortOrder" />
                <one-to-many class="datassist.payroll.entity.variable.Variable"/>
            </list>           
        </union-subclass>
       
        <union-subclass name="Unit">
            <many-to-one name="parentUnit" class="Unit"/>
           
            <list name="categories" table="unit_category" cascade="all, delete-orphan" >
                <key column="unit"/>
                <index column="sortOrder"/>
                <many-to-many class="Category" column="category"/>
            </list>
           
            <!--set name="employments" cascade="all, delete-orphan" >
                <key column="employer"/>
                <one-to-many class="Employment"/>
            </set-->
        </union-subclass>
       
        <union-subclass name="Employment">
            <many-to-one name="employer" class="Unit"/>
            <many-to-one name="employee" class="Employee"/>
            <property name="since"/>
            <property name="till"/>
        </union-subclass>
       
        <union-subclass name="Employee">
            <list name="employments" cascade="all, delete-orphan">
                <key column="employee"/>
                <list-index column="sortOrder"/>
                <one-to-many class="Employment" />
            </list>
            <set name="categories">
                <key column="employee"/>
                <many-to-many class="Category" column="category" />
            </set>
        </union-subclass>
    </class>
</hibernate-mapping>


and the Value:
Code:
<hibernate-mapping package="datassist.payroll.entity.value">
    <class name="Value" >
        <id name="id" unsaved-value="-1"><generator class="native"/></id>
        <discriminator column="type" type="string"/>

        <many-to-one name="item" class="datassist.payroll.entity.Item"/>
        <many-to-one name="variable" class="datassist.payroll.entity.variable.Variable"/>
        <property name="since"/>
        <property name="till"/>
        <property name="ffinal"/>
       
        <subclass name="BigDecimalValue" discriminator-value="N">
            <property name="core" column="bigDecimalCore"/>
        </subclass>
        <subclass name="DateValue" discriminator-value="D" >
            <property name="core" column="dateCore"/>
        </subclass>
        <subclass name="StringValue" discriminator-value="S" >
            <property name="core" column="stringCore"/>
        </subclass>
    </class>
</hibernate-mapping>


Here follows annotated versions of my classes:
Item:

Code:
@MappedSuperclass
abstract public class Item implements Serializable {
   
    @Id
    @GeneratedValue(strategy=GenerationType.AUTO)
    protected Long id=-1L;
   
    public String name;
    private String description;
    private boolean focused=false;
   
    @OneToMany
    @IndexColumn(name="sortOrder")
    @JoinColumn(name="item",referencedColumnName="id")
    private List<Value> values=new ArrayList<Value>();
    ...


Category is one of those classes that extends Item:
Code:
@Entity
public class Category extends Item implements Treeable<Category>, Serializable {
    private String type;
   
    @ManyToOne
    @JoinColumn(name="parentCategory")
    private Category parentCategory;
   
    @OneToMany(mappedBy="parentCategory")
    @IndexColumn(name="sortOrder")
    private List<Category> childCategories=new ArrayList<Category>();
   
    @OneToMany(mappedBy="category")
    @IndexColumn(name="sortOrder")
    private List<Variable> variables=new ArrayList<Variable>();
...


Value:
Code:
@Entity
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(name="type",discriminatorType=DiscriminatorType.STRING)
abstract public class Value implements Serializable {
   
    @Id
    private Long id=-1L;
   
//    @ManyToOne
    private Item item;
   
    @ManyToOne
    @JoinColumn(name="variable")
    protected Variable variable;
...


If I try @ManyToOne for the Item. It throws a mapping exception saying "Item" was not mapped.

Full stack trace of any exception that occurs:

While exporting schema it complains:
Code:
16:20:36,014 ERROR [SchemaExport] Unsuccessful: alter table Value add constraint FK4E9A151481D0FE5 foreign key (item) references Category
16:20:36,014 ERROR [SchemaExport] ERROR: foreign key constraint "fk4e9a151481d0fe5" cannot be implemented
  Detail: Key columns "item" and "id" are of incompatible types: bytea and bigint.
16:20:36,016 ERROR [SchemaExport] Unsuccessful: alter table Value add constraint FK4E9A1518C3D3995 foreign key (item) references Employee
16:20:36,016 ERROR [SchemaExport] ERROR: foreign key constraint "fk4e9a1518c3d3995" cannot be implemented
  Detail: Key columns "item" and "id" are of incompatible types: bytea and bigint.
16:20:36,017 ERROR [SchemaExport] Unsuccessful: alter table Value add constraint FK4E9A151B84B51D3 foreign key (item) references Employment
16:20:36,017 ERROR [SchemaExport] ERROR: foreign key constraint "fk4e9a151b84b51d3" cannot be implemented
  Detail: Key columns "item" and "id" are of incompatible types: bytea and bigint.
16:20:36,019 ERROR [SchemaExport] Unsuccessful: alter table Value add constraint FK4E9A151697E366B foreign key (item) references Unit
16:20:36,019 ERROR [SchemaExport] ERROR: foreign key constraint "fk4e9a151697e366b" cannot be implemented
  Detail: Key columns "item" and "id" are of incompatible types: bytea and bigint.

And when I triy to access values member it says:
Code:
javax.el.ELException: org.hibernate.exception.SQLGrammarException: could not initialize a collection: [datassist.payroll.entity.Category.values#1]
        at org.jboss.el.util.ReflectionUtil.invokeMethod(ReflectionUtil.java:332)
        at org.jboss.el.util.ReflectionUtil.invokeMethod(ReflectionUtil.java:273)
        at org.jboss.el.parser.AstMethodSuffix.getValue(AstMethodSuffix.java:59)
        at org.jboss.el.parser.AstMethodSuffix.invoke(AstMethodSuffix.java:65)
        at org.jboss.el.parser.AstValue.invoke(AstValue.java:96)
        at org.jboss.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:276)
        at org.jboss.seam.core.Expressions$2.invoke(Expressions.java:174)
        at org.jboss.seam.navigation.Pages.callAction(Pages.java:634)
        at org.jboss.seam.navigation.Pages.preRender(Pages.java:289)
        at org.jboss.seam.jsf.SeamPhaseListener.preRenderPage(SeamPhaseListener.java:544)
        at org.jboss.seam.jsf.SeamPhaseListener.beforeRenderResponse(SeamPhaseListener.java:455)
        at org.jboss.seam.jsf.SeamPhaseListener.beforeServletPhase(SeamPhaseListener.java:146)
        at org.jboss.seam.jsf.SeamPhaseListener.beforePhase(SeamPhaseListener.java:116)
        at com.sun.faces.lifecycle.LifecycleImpl.phase(LifecycleImpl.java:222)
        at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:144)
        at javax.faces.webapp.FacesServlet.service(FacesServlet.java:245)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
        at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:83)
        at org.jboss.seam.debug.hot.HotDeployFilter.doFilter(HotDeployFilter.java:68)
        at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
        at org.jboss.seam.web.MultipartFilter.doFilter(MultipartFilter.java:85)
        at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
        at org.jboss.seam.web.ExceptionFilter.doFilter(ExceptionFilter.java:64)
        at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
        at org.jboss.seam.web.RedirectFilter.doFilter(RedirectFilter.java:44)
        at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
        at org.ajax4jsf.webapp.BaseXMLFilter.doXmlFilter(BaseXMLFilter.java:141)
        at org.ajax4jsf.webapp.BaseFilter.doFilter(BaseFilter.java:281)
        at org.jboss.seam.web.Ajax4jsfFilter.doFilter(Ajax4jsfFilter.java:60)
        at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
        at org.jboss.seam.web.LoggingFilter.doFilter(LoggingFilter.java:58)
        at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
        at org.jboss.seam.servlet.SeamFilter.doFilter(SeamFilter.java:158)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
        at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
        at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:230)
        at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
        at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:179)
        at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:84)
        at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
        at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
        at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:157)
        at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
        at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:262)
        at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
        at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
        at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:446)
        at java.lang.Thread.run(Thread.java:595)
Caused by: org.hibernate.exception.SQLGrammarException: could not initialize a collection: [datassist.payroll.entity.Category.values#1]
        at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:67)
        at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
        at org.hibernate.loader.Loader.loadCollection(Loader.java:2001)
        at org.hibernate.loader.collection.CollectionLoader.initialize(CollectionLoader.java:36)
        at org.hibernate.persister.collection.AbstractCollectionPersister.initialize(AbstractCollectionPersister.java:565)
        at org.hibernate.event.def.DefaultInitializeCollectionEventListener.onInitializeCollection(DefaultInitializeCollectionEventListener.java:60)
        at org.hibernate.impl.SessionImpl.initializeCollection(SessionImpl.java:1716)
        at org.hibernate.collection.AbstractPersistentCollection.initialize(AbstractPersistentCollection.java:344)
        at org.hibernate.collection.AbstractPersistentCollection.read(AbstractPersistentCollection.java:86)
        at org.hibernate.collection.AbstractPersistentCollection.readSize(AbstractPersistentCollection.java:109)
        at org.hibernate.collection.PersistentList.size(PersistentList.java:91)
        at datassist.payroll.entity.Item.getCopyOfValues(Item.java:332)
        at datassist.payroll.entity.Item.focus(Item.java:187)
        at datassist.payroll.entity.Item.edit(Item.java:168)
        at datassist.payroll.action.CategoryAction.define(CategoryAction.java:119)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:585)
        at org.jboss.seam.util.Reflections.invoke(Reflections.java:21)
        at org.jboss.seam.intercept.RootInvocationContext.proceed(RootInvocationContext.java:31)
        at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:56)
        at org.jboss.seam.core.BijectionInterceptor.aroundInvoke(BijectionInterceptor.java:46)
        at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
        at org.jboss.seam.persistence.ManagedEntityIdentityInterceptor.aroundInvoke(ManagedEntityIdentityInterceptor.java:48)
        at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
        at org.jboss.seam.transaction.RollbackInterceptor.aroundInvoke(RollbackInterceptor.java:31)
        at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
        at org.jboss.seam.core.ConversationInterceptor.aroundInvoke(ConversationInterceptor.java:56)
        at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
        at org.jboss.seam.core.MethodContextInterceptor.aroundInvoke(MethodContextInterceptor.java:42)
        at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
        at org.jboss.seam.intercept.RootInterceptor.invoke(RootInterceptor.java:106)
        at org.jboss.seam.intercept.JavaBeanInterceptor.interceptInvocation(JavaBeanInterceptor.java:155)
        at org.jboss.seam.intercept.JavaBeanInterceptor.invoke(JavaBeanInterceptor.java:91)
        at datassist.payroll.action.CategoryAction_$$_javassist_2.define(CategoryAction_$$_javassist_2.java)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:585)
        at org.jboss.el.util.ReflectionUtil.invokeMethod(ReflectionUtil.java:328)
        ... 51 more
Caused by: org.postgresql.util.PSQLException: ERROR: operator does not exist: bytea = bigint
        at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:1548)
        at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1316)
        at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:191)
        at org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:452)
        at org.postgresql.jdbc2.AbstractJdbc2Statement.executeWithFlags(AbstractJdbc2Statement.java:351)
        at org.postgresql.jdbc2.AbstractJdbc2Statement.executeQuery(AbstractJdbc2Statement.java:255)
        at org.jboss.resource.adapter.jdbc.WrappedPreparedStatement.executeQuery(WrappedPreparedStatement.java:236)
        at org.hibernate.jdbc.AbstractBatcher.getResultSet(AbstractBatcher.java:186)
        at org.hibernate.loader.Loader.getResultSet(Loader.java:1787)
        at org.hibernate.loader.Loader.doQuery(Loader.java:674)
        at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:236)
        at org.hibernate.loader.Loader.loadCollection(Loader.java:1994)


Name and version of the database you are using:
Postgresql 8x


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.