Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Blocker Blocker
    • Resolution: Rejected
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: None
    • Labels:
      None
    • Environment:
      Hibernate-3.1-alpha1, Hibernate-Annotations-3.1-beta3, ejb-3.0-erd2, jdk1.5.0_3, MySql 4.0, mysql-connector-java-3.1.7
    • Bug Testcase Reminder (view):

      Bug reports should generally be accompanied by a test case!

    • Last commented by a user?:
      true

      Description

      @Column annotations on a getters within an @Embeddable object are getting ignored. The embeddable is seen but the generated sql is using the properties and not the column name.

      Below is the code.

      ------------------------------------------------------------------------

      package com.dolby.pics.core.db.model.impl;

      import java.util.HashSet;
      import java.util.Set;

      import javax.persistence.Column;
      import javax.persistence.Embedded;
      import javax.persistence.Entity;
      import javax.persistence.GeneratorType;
      import javax.persistence.Id;
      import javax.persistence.NamedQueries;
      import javax.persistence.NamedQuery;
      import javax.persistence.Table;

      import org.apache.commons.lang.builder.EqualsBuilder;
      import org.apache.commons.lang.builder.HashCodeBuilder;

      import com.dolby.pics.core.db.model.IBusinessUnit;
      import com.dolby.pics.core.db.util.EntityObject;
      import com.dolby.pics.core.db.util.ILifecycle;

      /**

      • @author <a href="mailto:djb@dolby.co.uk">Darren Bell</a> - Dolby Laboratories Inc.
      • Data class for Business Units
        */

      @Entity
      @Table(name="BUSINESS_UNIT", schema="ZCOREINV")
      @NamedQueries({
      @NamedQuery(
      name="query.BusinessUnit.single.byName",
      queryString="from BusinessUnit bu where bu.name = :name"),
      @NamedQuery(
      name="query.BusinessUnit.all",
      queryString="from BusinessUnit bu")
      })
      public class BusinessUnit extends EntityObject implements IBusinessUnit
      {
      /**

      • */
        private static final long serialVersionUID = 4120848867379065142L;

      /** query to return a business unit by name */
      public static final String QUERY_BY_NAME = "query.BusinessUnit.single.byName"; //$NON-NLS-1$

      /** query to return all business units */
      public static final String QUERY_ALL = "query.BusinessUnit.all"; //$NON-NLS-1$

      /** name attribute */
      public static final String ATTR_NAME = "name"; //$NON-NLS-1$

      private String fName;

      private String fDescription;

      /** The lifecycle for this entity */
      protected ILifecycle fLifecycle;

      /**

      • default cons
        */
        BusinessUnit() { super(); }

        /**
        * Creates a new business unit with the given name
        * @param name The name for this business unit
        */
        public BusinessUnit(final String name)
        { this(name, null); }

        /**
        * Creates a business unit with the provided name and description
        * @param name Name of business unit
        * @param desc Business unit description
        */
        public BusinessUnit(final String name, final String desc)
        { super(); setName(name); setDescription(desc); }

        /**
        * Returns the description for this business unit
        * @return Returns the description.
        */
        @Column(name="BU_DESCRIPTION", length=128, nullable=false)
        public String getDescription()
        { return fDescription; }

        /**
        * Sets the description for this business unit
        * @param description The description to set.
        */
        public void setDescription(final String description)
        { fDescription = description; }

        /**
        * Gets the name of this business unit
        * @return Returns the name.
        * @hibernate.id
        * unsaved-value="null"
        * generator-class="assigned"
        * column="BU_NAME"
        * type="string"
        * length="5"
        */
        @Id(generate=GeneratorType.NONE)
        @Column(name="BU_NAME")
        public String getName()
        { return fName; }

        /**
        * Sets the name for this business unit
        * @param name The name to set.
        */
        private void setName(final String name)
        { fName = name; }

        /**
        * Return a string rpresentation of this business unit
        * @see java.lang.Object#toString()
        */
        public String toString()
        { return getName(); }
        /**
        * @see java.lang.Object#equals(java.lang.Object)
        */
        public boolean equals(final Object obj)
        {
        // do NOT use instanceof!
        if (obj != null && getClass() == obj.getClass())
        { //BusinessUnit rhs = (BusinessUnit) obj; return new EqualsBuilder() .append(getName(), ((IBusinessUnit) obj).getName()) .isEquals(); }
        return false;
        }

        /**
        * @see java.lang.Object#hashCode()
        */
        public int hashCode()
        { return new HashCodeBuilder(17, 37) .append(getName()) .toHashCode(); }

        /**
        * Sets the new lifecycle for this entity
        * @param lifecycle The new lifecycle
        */
        protected void setLifecycle(final ILifecycle lifecycle) { fLifecycle = lifecycle; }

        /**
        * Gets the lifecycle object for this entity
        * @see com.dolby.pics.core.db.system.IEntityLifecycle#getLifecycle()
        * @return This entitys lifecycle
        */
        @Embedded
        public final ILifecycle getLifecycle() { return fLifecycle; }
        }

        --------------------------------------------------------------------

        /* Copyright 2005 Dolby Laboratories Inc. All rights reserved.
        * See license distributed with this file or available at
        * http://ukdev/license.html
        */
        package com.dolby.pics.core.db.util;

        import java.io.Serializable;
        import java.sql.Timestamp;

        import javax.persistence.AccessType;
        import javax.persistence.Basic;
        import javax.persistence.Column;
        import javax.persistence.Embeddable;
        import javax.persistence.Transient;

        /**
        * @author <a href="mailto:djb@dolby.co.uk">Darren Bell</a> - Dolby Laboratories Inc.
        */
        @Embeddable
        public class Lifecycle implements ILifecycle, Cloneable, Serializable
        {
        /**
        *
        */
        private static final long serialVersionUID = 3257565113824588089L;

        /** User who created this entity object */
        private String fCreatedByUser;

        /** The system that is creating/created this object */
        private String fCreatedBySystem;

        /** The date/time that this object was created */
        private Timestamp fCreatedTimestamp;

        /** the user who is updating/updated this object */
        private String fUpdatedByUser;

        /** the system that is updating/updated this object */
        private String fUpdatedBySystem;

        /** the date/time that this object is being/was updated */
        private Timestamp fUpdatedTimestamp;

        /**
        * Creates a new lifecycle object
        */
        Lifecycle()
        { super(); }

      /**

      • @see com.dolby.pics.core.db.system.ILifecycle#getCreatedByUser()
        */
        @Column(name="CREATED_BY_USER", nullable=false, length=32, columnDefinition="varchar(32)", updatable=false)
        public String getCreatedByUser() { return fCreatedByUser; }

      /**

      • @see com.dolby.pics.core.db.system.ILifecycle#getCreatedBySystem()
        */
        @Column(name="CREATED_BY_SYSTEM", nullable=false, length=32, updatable=false)
        public String getCreatedBySystem() { return fCreatedBySystem; }

      /**

      • @see com.dolby.pics.core.db.system.ILifecycle#getCreatedTimestamp()
      • @return the timestamp when the object was created
        */
        @Column(name="CREATED_TIMESTAMP", nullable=false, updatable=false)
        public Timestamp getCreatedTimestamp() { return fCreatedTimestamp; }

      /**

      • @see com.dolby.pics.core.db.system.ILifecycle#setCreatedByUser(java.lang.String)
        */
        public void setCreatedByUser(final String createByUser) { fCreatedByUser = createByUser; }

      /**

      • @see com.dolby.pics.core.db.system.ILifecycle#setCreatedBySystem(java.lang.String)
        */
        public void setCreatedBySystem(final String createdBySystem) { fCreatedBySystem = createdBySystem; }

      /**

      • @see com.dolby.pics.core.db.system.ILifecycle#setCreatedTimestamp(java.sql.Timestamp)
        */
        public void setCreatedTimestamp(final Timestamp createdTimestamp) { fCreatedTimestamp = createdTimestamp; }

      /**

      • @see com.dolby.pics.core.db.system.ILifecycle#getUpdatedByUser()
        */
        @Column(name="UPDATED_BY_USER", length=32, insertable=false)
        public String getUpdatedByUser() { return fUpdatedByUser; }

      /**

      • @return the system that updated this object
        */
        @Column(name="UPDATED_BY_SYSTEM", length=32, insertable=false)
        public String getUpdatedBySystem() { return fUpdatedBySystem; }

      /**

      • @return The time and date this entity was changed
      • @see com.dolby.pics.core.db.system.ILifecycle#getUpdatedTimestamp()
        */
        @Column(name="UPDATED_TIMESTAMP", insertable=false)
        public Timestamp getUpdatedTimestamp() { return fUpdatedTimestamp; }

      /**

      • @param updatedByUser
      • @see com.dolby.pics.core.db.system.ILifecycle#setUpdatedByUser(java.lang.String)
        */
        public void setUpdatedByUser(final String updatedByUser) { fUpdatedByUser = updatedByUser; }

      /**

      • @param updatedBySystem
      • @see com.dolby.pics.core.db.system.ILifecycle#setUpdatedBySystem(java.lang.String)
        */
        public void setUpdatedBySystem(final String updatedBySystem) { fUpdatedBySystem = updatedBySystem; }

      /**

      • @see com.dolby.pics.core.db.system.ILifecycle#setUpdatedTimestamp(java.sql.Timestamp)
        */
        public void setUpdatedTimestamp(final Timestamp updatedTimestamp) { fUpdatedTimestamp = updatedTimestamp; }

      /**

      • @see java.lang.Object#clone()
        */
        protected Object clone() throws CloneNotSupportedException { Lifecycle clonedLifecycle = new Lifecycle(); clonedLifecycle.setCreatedBySystem(getCreatedBySystem()); clonedLifecycle.setCreatedByUser(getCreatedByUser()); clonedLifecycle.setCreatedTimestamp(getCreatedTimestamp()); clonedLifecycle.setUpdatedBySystem(getUpdatedBySystem()); clonedLifecycle.setUpdatedByUser(getUpdatedByUser()); clonedLifecycle.setUpdatedTimestamp(getUpdatedTimestamp()); return clonedLifecycle; }

      /**

      • Return a formatted string for this lifecycle
      • @see java.lang.Object#toString()
        */
        public String toString()
        Unknown macro: { //String TO_STRING = "[CREATED}

        }

      ---------------------------------------------------------------------

      Here is the log output.

      27-Jun-2005 11:35:15 org.hibernate.cfg.Environment <clinit>
      INFO: Hibernate 3.1alpha1
      27-Jun-2005 11:35:15 org.hibernate.cfg.Environment <clinit>
      INFO: hibernate.properties not found
      27-Jun-2005 11:35:15 org.hibernate.cfg.Environment <clinit>
      INFO: using CGLIB reflection optimizer
      27-Jun-2005 11:35:15 org.hibernate.cfg.Environment <clinit>
      INFO: using JDK 1.4 java.sql.Timestamp handling
      27-Jun-2005 11:35:15 org.hibernate.cfg.Configuration configure
      INFO: configuring from resource: /hibernate.cfg.xml
      27-Jun-2005 11:35:15 org.hibernate.cfg.Configuration getConfigurationInputStream
      INFO: Configuration resource: /hibernate.cfg.xml
      27-Jun-2005 11:35:15 org.hibernate.cfg.Configuration doConfigure
      INFO: Configured SessionFactory: null
      27-Jun-2005 11:35:15 org.hibernate.cfg.Configuration secondPassCompile
      INFO: processing extends queue
      27-Jun-2005 11:35:15 org.hibernate.cfg.Configuration secondPassCompile
      INFO: processing collection mappings
      27-Jun-2005 11:35:15 org.hibernate.cfg.Configuration secondPassCompile
      INFO: processing association property references
      27-Jun-2005 11:35:15 org.hibernate.cfg.Configuration secondPassCompile
      INFO: processing foreign key constraints
      27-Jun-2005 11:35:16 org.hibernate.connection.DriverManagerConnectionProvider configure
      INFO: Using Hibernate built-in connection pool (not for production use!)
      27-Jun-2005 11:35:16 org.hibernate.connection.DriverManagerConnectionProvider configure
      INFO: Hibernate connection pool size: 20
      27-Jun-2005 11:35:16 org.hibernate.connection.DriverManagerConnectionProvider configure
      INFO: autocommit mode: false
      27-Jun-2005 11:35:16 org.hibernate.connection.DriverManagerConnectionProvider configure
      INFO: using driver: com.mysql.jdbc.Driver at URL: jdbc:mysql://auk.dolby.net/coreinv
      27-Jun-2005 11:35:16 org.hibernate.connection.DriverManagerConnectionProvider configure
      INFO: connection properties:

      {user=pics, password=****}

      27-Jun-2005 11:35:16 org.hibernate.cfg.SettingsFactory buildSettings
      INFO: RDBMS: MySQL, version: 4.0.18-max
      27-Jun-2005 11:35:16 org.hibernate.cfg.SettingsFactory buildSettings
      INFO: JDBC driver: MySQL-AB JDBC Driver, version: mysql-connector-java-3.1.7 ( $Date: 2005/01/25 19:11:41 $, $Revision: 1.27.4.54 $ )
      27-Jun-2005 11:35:16 org.hibernate.dialect.Dialect <init>
      INFO: Using dialect: org.hibernate.dialect.MySQLDialect
      27-Jun-2005 11:35:16 org.hibernate.transaction.TransactionFactoryFactory buildTransactionFactory
      INFO: Using default transaction strategy (direct JDBC transactions)
      27-Jun-2005 11:35:16 org.hibernate.transaction.TransactionManagerLookupFactory getTransactionManagerLookup
      INFO: No TransactionManagerLookup configured (in JTA environment, use of read-write or transactional second-level cache is not recommended)
      27-Jun-2005 11:35:16 org.hibernate.cfg.SettingsFactory buildSettings
      INFO: Automatic flush during beforeCompletion(): disabled
      27-Jun-2005 11:35:16 org.hibernate.cfg.SettingsFactory buildSettings
      INFO: Automatic session close at end of transaction: disabled
      27-Jun-2005 11:35:16 org.hibernate.cfg.SettingsFactory buildSettings
      INFO: JDBC batch size: 15
      27-Jun-2005 11:35:16 org.hibernate.cfg.SettingsFactory buildSettings
      INFO: JDBC batch updates for versioned data: disabled
      27-Jun-2005 11:35:16 org.hibernate.cfg.SettingsFactory buildSettings
      INFO: Scrollable result sets: enabled
      27-Jun-2005 11:35:16 org.hibernate.cfg.SettingsFactory buildSettings
      INFO: JDBC3 getGeneratedKeys(): enabled
      27-Jun-2005 11:35:16 org.hibernate.cfg.SettingsFactory buildSettings
      INFO: Connection release mode: null
      27-Jun-2005 11:35:16 org.hibernate.cfg.SettingsFactory buildSettings
      INFO: Maximum outer join fetch depth: 2
      27-Jun-2005 11:35:16 org.hibernate.cfg.SettingsFactory buildSettings
      INFO: Default batch fetch size: 1
      27-Jun-2005 11:35:16 org.hibernate.cfg.SettingsFactory buildSettings
      INFO: Generate SQL with comments: disabled
      27-Jun-2005 11:35:16 org.hibernate.cfg.SettingsFactory buildSettings
      INFO: Order SQL updates by primary key: disabled
      27-Jun-2005 11:35:16 org.hibernate.cfg.SettingsFactory createQueryTranslatorFactory
      INFO: Query translator: org.hibernate.hql.ast.ASTQueryTranslatorFactory
      27-Jun-2005 11:35:16 org.hibernate.hql.ast.ASTQueryTranslatorFactory <init>
      INFO: Using ASTQueryTranslatorFactory
      27-Jun-2005 11:35:16 org.hibernate.cfg.SettingsFactory buildSettings
      INFO: Query language substitutions: {}
      27-Jun-2005 11:35:16 org.hibernate.cfg.SettingsFactory buildSettings
      INFO: Second-level cache: enabled
      27-Jun-2005 11:35:16 org.hibernate.cfg.SettingsFactory buildSettings
      INFO: Query cache: disabled
      27-Jun-2005 11:35:16 org.hibernate.cfg.SettingsFactory createCacheProvider
      INFO: Cache provider: org.hibernate.cache.EhCacheProvider
      27-Jun-2005 11:35:16 org.hibernate.cfg.SettingsFactory buildSettings
      INFO: Optimize cache for minimal puts: disabled
      27-Jun-2005 11:35:16 org.hibernate.cfg.SettingsFactory buildSettings
      INFO: Structured second-level cache entries: disabled
      27-Jun-2005 11:35:16 org.hibernate.cfg.SettingsFactory buildSettings
      INFO: Echoing all SQL to stdout
      27-Jun-2005 11:35:16 org.hibernate.cfg.SettingsFactory buildSettings
      INFO: Statistics: disabled
      27-Jun-2005 11:35:16 org.hibernate.cfg.SettingsFactory buildSettings
      INFO: Deleted entity synthetic identifier rollback: disabled
      27-Jun-2005 11:35:16 org.hibernate.cfg.SettingsFactory buildSettings
      INFO: Default entity-mode: pojo
      27-Jun-2005 11:35:16 org.hibernate.impl.SessionFactoryImpl <init>
      INFO: building session factory
      27-Jun-2005 11:35:16 net.sf.ehcache.config.Configurator configure
      WARNING: No configuration found. Configuring ehcache from ehcache-failsafe.xml found in the classpath: jar:file:/home/djb/.maven/repository/ehcache/jars/ehcache-1.1.jar!/ehcache-failsafe.xml
      27-Jun-2005 11:35:16 org.hibernate.tuple.PojoTuplizer buildProxyFactory
      SEVERE: Getters of lazy classes cannot be final: com.dolby.pics.core.db.model.impl.BusinessUnit.lifecycle
      27-Jun-2005 11:35:16 org.hibernate.impl.SessionFactoryObjectFactory addInstance
      INFO: Not binding factory to JNDI, no JNDI name configured
      27-Jun-2005 11:35:16 org.hibernate.impl.SessionFactoryImpl checkNamedQueries
      INFO: Checking 2 named queries
      Hibernate: select businessun0_.BU_NAME as BU1_, businessun0_.BU_DESCRIPTION as BU2_0_, businessun0_.createdByUser as createdB3_0_, businessun0_.createdBySystem as createdB4_0_, businessun0_.createdTimestamp as createdT5_0_, businessun0_.updatedByUser as updatedB6_0_, businessun0_.updatedBySystem as updatedB7_0_, businessun0_.updatedTimestamp as updatedT8_0_ from ZCOREINV_BUSINESS_UNIT businessun0_
      27-Jun-2005 11:35:17 org.hibernate.util.JDBCExceptionReporter logExceptions
      WARNING: SQL Error: 1054, SQLState: 42S22
      27-Jun-2005 11:35:17 org.hibernate.util.JDBCExceptionReporter logExceptions
      SEVERE: Unknown column 'businessun0_.createdByUser' in 'field list'
      Exception in thread "main" org.hibernate.exception.SQLGrammarException: could not execute query
      at org.hibernate.exception.ErrorCodeConverter.convert(ErrorCodeConverter.java:70)
      at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
      at org.hibernate.loader.Loader.doList(Loader.java:1861)
      at org.hibernate.loader.Loader.list(Loader.java:1842)
      at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:407)
      at org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:273)
      at org.hibernate.impl.SessionImpl.list(SessionImpl.java:850)
      at org.hibernate.impl.QueryImpl.list(QueryImpl.java:74)
      at Go.main(Go.java:22)
      Caused by: java.sql.SQLException: Unknown column 'businessun0_.createdByUser' in 'field list'
      at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2847)
      at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1531)
      at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1622)
      at com.mysql.jdbc.Connection.execSQL(Connection.java:2376)
      at com.mysql.jdbc.Connection.execSQL(Connection.java:2297)
      at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1860)
      at com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:1705)
      at org.hibernate.jdbc.AbstractBatcher.getResultSet(AbstractBatcher.java:120)
      at org.hibernate.loader.Loader.getResultSet(Loader.java:1537)
      at org.hibernate.loader.Loader.doQuery(Loader.java:638)
      at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:221)
      at org.hibernate.loader.Loader.doList(Loader.java:1858)
      ... 6 more

      Thanks

        Activity

        Hide
        Emmanuel Bernard added a comment -

        How the Annotation binder is supposed to know that ILifeCycle metadata has to be found in LifeCycle implementation.

        Show
        Emmanuel Bernard added a comment - How the Annotation binder is supposed to know that ILifeCycle metadata has to be found in LifeCycle implementation.
        Hide
        Darren Bell added a comment -

        Yup, i agree with you there, but, using an hbm.xml file i can specify a component as follows.

        <component
        name="lifecycle"
        class="com.dolby.pics.core.db.system.Lifecycle"
        >

        Is there anyway i can specify a class on the @Embedded tag?

        This is a show stooper as our entire object model uses this framework.

        Show
        Darren Bell added a comment - Yup, i agree with you there, but, using an hbm.xml file i can specify a component as follows. <component name="lifecycle" class="com.dolby.pics.core.db.system.Lifecycle" > Is there anyway i can specify a class on the @Embedded tag? This is a show stooper as our entire object model uses this framework.
        Hide
        Emmanuel Bernard added a comment -

        This one is interesting.
        Please send this feedback tot he EJB3 EG, we probably should add something like @Embeddable(targetEmbeddable default void.class)

        Show
        Emmanuel Bernard added a comment - This one is interesting. Please send this feedback tot he EJB3 EG, we probably should add something like @Embeddable(targetEmbeddable default void.class)
        Hide
        Darren Bell added a comment -

        How do i send feedback to the EJB EG? Just been on the JCP page and it was not obvious.

        Show
        Darren Bell added a comment - How do i send feedback to the EJB EG? Just been on the JCP page and it was not obvious.
        Hide
        Darren Bell added a comment -

        Sorted

        Show
        Darren Bell added a comment - Sorted

          People

          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: