1 Reply Latest reply on Feb 10, 2006 2:18 PM by dunks80

    @AttributeOverrides question

    dunks80 Newbie

      I must be missing something because I can't get @AttributeOverrides to actually override the mapping laid down in the superclass...

      Here is my MappedSuperclass...

      @MappedSuperclass
      public abstract class ShipmentItem<ShipmentType extends Shipment,ItemType extends Entity> extends Entity
      {
       //relationship
       protected ShipmentType shipment;
       protected ItemType item;
       //attributes
       private Integer quantity;
      
       public ShipmentItem()
       {
       super();
       }
      
       public Integer getQuantity()
       {
       return quantity;
       }
      
       public void setQuantity(Integer quantity)
       {
       this.quantity = quantity;
       }
      
      
      
      
      
       @ManyToOne(fetch = FetchType.LAZY)
       @JoinColumn(name = "itemId")
       public ItemType getItem()
       {
      
       return item;
       }
      
      
       public void setItem(ItemType item)
       {
       this.item=item;
       }
      
      
       @ManyToOne(fetch = FetchType.LAZY)
       @JoinColumn(name = "shipmentId")
       public ShipmentType getShipment()
       {
      
       return shipment;
       }
      
      
       public void setShipment(ShipmentType shipment)
       {
       this.shipment=shipment;
       }
      
      }
      


      Then i have a concreate subclass that looks like this...

      @Entity
      @Table(name = "colorBreakShipment")
       @AttributeOverrides( {
       @AttributeOverride(name = "item", column = @Column(name = "colorBreakId")),
       @AttributeOverride(name = "shipment", column = @Column(name = "colorBreakShipmentId"))
       })
      public class ColorBreakShipmentItem extends ShipmentItem<ColorBreakShipment, ColorBreak>
      {
      
      
       public ColorBreakShipmentItem()
       {
       super();
       }
      }
      


      when i test the entity I get the following exception...

      Caused by: org.hibernate.exception.SQLGrammarException: could not initialize a collection: [com.tura.insight.core.entity.ColorBreak.colorBreakShipmentItems#2715]
       at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:65)
       at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
       at org.hibernate.loader.Loader.loadCollection(Loader.java:1926)
       at org.hibernate.loader.collection.CollectionLoader.initialize(CollectionLoader.java:71)
       at org.hibernate.persister.collection.AbstractCollectionPersister.initialize(AbstractCollectionPersister.java:520)
       at org.hibernate.event.def.DefaultInitializeCollectionEventListener.onInitializeCollection(DefaultInitializeCollectionEventListener.java:60)
       at org.hibernate.impl.SessionImpl.initializeCollection(SessionImpl.java:1695)
       at org.hibernate.collection.AbstractPersistentCollection.initialize(AbstractPersistentCollection.java:344)
       at org.hibernate.collection.AbstractPersistentCollection.read(AbstractPersistentCollection.java:86)
       at org.hibernate.collection.PersistentBag.iterator(PersistentBag.java:246)
       at com.tura.insight.core.command.EntityInitializationExpressionParser.touch(EntityInitializationExpressionParser.java:240)
       at com.tura.insight.core.command.EntityInitializationExpressionParser.parseExpression(EntityInitializationExpressionParser.java:225)
       at com.tura.insight.core.command.EntityInitializationExpressionParser.parseExpression(EntityInitializationExpressionParser.java:136)
       at com.tura.insight.core.command.CommandProcessor.parseResultInitializationExpression(CommandProcessor.java:61)
       at com.tura.insight.core.service.ServiceDelegateImpl.initializeResult(ServiceDelegateImpl.java:111)
       at com.tura.insight.core.service.ServiceDelegateImpl.processCommand(ServiceDelegateImpl.java:82)
       at com.tura.insight.core.service.ServiceDelegateImpl.execute(ServiceDelegateImpl.java:49)
       at jrockit.reflect.VirtualNativeMethodInvoker.invoke(Ljava.lang.Object;[Ljava.lang.Object;)Ljava.lang.Object;(Unknown Source)
       at java.lang.reflect.Method.invoke(Ljava.lang.Object;[Ljava.lang.Object;J)Ljava.lang.Object;(Unknown Source)
      Caused by: java.sql.SQLException: Invalid column name 'itemId'.
       at net.sourceforge.jtds.jdbc.SQLDiagnostic.addDiagnostic(SQLDiagnostic.java:365)
       at net.sourceforge.jtds.jdbc.TdsCore.tdsErrorToken(TdsCore.java:2781)
       at net.sourceforge.jtds.jdbc.TdsCore.nextToken(TdsCore.java:2224)
       at net.sourceforge.jtds.jdbc.TdsCore.getMoreResults(TdsCore.java:628)
       at net.sourceforge.jtds.jdbc.JtdsStatement.executeSQLQuery(JtdsStatement.java:418)
       at net.sourceforge.jtds.jdbc.JtdsPreparedStatement.executeQuery(JtdsPreparedStatement.java:693)
       at org.jboss.resource.adapter.jdbc.WrappedPreparedStatement.executeQuery(WrappedPreparedStatement.java:236)
       at org.hibernate.jdbc.AbstractBatcher.getResultSet(AbstractBatcher.java:139)
       at org.hibernate.loader.Loader.getResultSet(Loader.java:1669)
       at org.hibernate.loader.Loader.doQuery(Loader.java:662)
       at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:224)
       at org.hibernate.loader.Loader.loadCollection(Loader.java:1919)
       at org.hibernate.loader.collection.CollectionLoader.initialize(CollectionLoader.java:71)
       at org.hibernate.persister.collection.AbstractCollectionPersister.initialize(AbstractCollectionPersister.java:520)
       at org.hibernate.event.def.DefaultInitializeCollectionEventListener.onInitializeCollection(DefaultInitializeCollectionEventListener.java:60)
       at org.hibernate.impl.SessionImpl.initializeCollection(SessionImpl.java:1695)
       at org.hibernate.collection.AbstractPersistentCollection.initialize(AbstractPersistentCollection.java:344)
       at org.hibernate.collection.AbstractPersistentCollection.read(AbstractPersistentCollection.java:86)
       at org.hibernate.collection.PersistentBag.iterator(PersistentBag.java:246)
       at com.tura.insight.core.command.EntityInitializationExpressionParser.touch(EntityInitializationExpressionParser.java:240)
       at com.tura.insight.core.command.EntityInitializationExpressionParser.parseExpression(EntityInitializationExpressionParser.java:225)
       at com.tura.insight.core.command.EntityInitializationExpressionParser.parseExpression(EntityInitializationExpressionParser.java:136)
       at com.tura.insight.core.command.CommandProcessor.parseResultInitializationExpression(CommandProcessor.java:61)
       at com.tura.insight.core.service.ServiceDelegateImpl.initializeResult(ServiceDelegateImpl.java:111)
       at com.tura.insight.core.service.ServiceDelegateImpl.processCommand(ServiceDelegateImpl.java:82)
       at com.tura.insight.core.service.ServiceDelegateImpl.execute(ServiceDelegateImpl.java:49)
      
      


      Based on the example in the latest version of the spec for @AttributeOverride and @AttributeOverrides I would think this would work? Is it because my super class is generic? I shouldd mention I'm still using ejb3.0 rc4