Hi Dennis,
According to the spec sections 2.1.4, 9.1.14, and 9.1.15 you either have all the
fields in the Embeddable or use IdClass to duplicate the fields, but in the
latter case all the mapping stays with the entity and you don't need
'updateable/insertable' work around.
Regards,
-marina
Dennis Gesker wrote:
> Marina, Gary:
>
> Thank you for pointing me in the right direction.
>
> I gave Gary's recommendation a try as it required the smallest amount of
> change to my existing classes.
>
> However, I'm curious as to which of these approaches are considered a
> best practice. I can surely see benefits in both approaches.
>
> In any event I'm grateful to you both.
>
> Dennis
>
> On Wed, Apr 23, 2008 at 10:59 AM, Marina Vatkina <Marina.Vatkina_at_sun.com
> <mailto:Marina.Vatkina_at_sun.com>> wrote:
>
> Your entity should not duplicate the columns that are part of
> @EmbeddedId - they will be picked up from there.
>
> Regards,
> -marina
>
> Dennis Gesker wrote:
>
> Yes. 8 columns that comprise the natural PK. The insert
> statement generated looks like this (I've bolded the duplicates
> and I assume the same colums from the Embeddable are the last
> eight duplicate columns):
>
> INSERT INTO dbo.aesop_WorkHistoryAlamon (SurchargeLoad,
> LoadedSurcharge, *CustomerNumber*, LoadedSurchargeCost,
> *ContractNumber*, SurchargeBillRate, *ProjectNumber*,
> SurchargeBillUnits, *ProjectClassID*, SurchargeBilled,
> *EmployeeID*, VehicleUnitOfMeasure, MiddleName, Vehicle,
> *JobTitle*, VehicleUnits, *Week*, VehicleCost, Wage,
> VehicleLoad, WageCost, LoadedVehicle, LoadedWage,
> LoadedVehicleCost, WageBillRate, VehicleBillRate, WageBilled,
> VehicleBillUnits, OverTime, VehicleBilled, OverTimeCost,
> MileageUnitOfMeasure, LoadedOverTime, Mileage, OverTimeBillRate,
> MileageUnits, OverTimeBilled, MileageCost, PerDiem, MileageLoad,
> PerDiemCost, LoadedMileage, LoadedPerDiem, LoadedMileageCost,
> PerDiemBillRate, MileageBillRate, PerDiemBilled,
> MileageBillUnits, Surcharge, MileageBilled, SurchargeCost,
> ReimburseUnitOfMeasure, CustomerName, Reimburse, ProjectName,
> ReimburseUnits, FirstName, ReimburseCost, *Year*, ReimburseLoad,
> WageUnits, LoadedReimburse, LoadedWageCost, LoadedReimburseCost,
> OverTimeUnitOfMeasure, ReimburseBillRate, OverTimeLoad,
> ReimburseBillUnits, OverTimeBillUnits, ReimburseBilled,
> PerDiemUnits, PVHUnitOfMeasure, LoadedPerDiemCost, PVH,
> SurchargeUnitOfMeasure, PVHUnits, ContractName,
> ScenarioMarginPerHoursWorked, PVHCost, LastName, PVHLoad,
> WageLoad, LoadedPVH, OverTimeUnits, LoadedPVHCost,
> PerDiemUnitOfMeasure, PVHBillRate, PerDiemBillUnits,
> PVHBillUnits, ProjectType, PVHBilled, WageBillUnits,
> ScenarioCost, PerDiemLoad, ScenarioBilled, WageUnitOfMeasure,
> ScenarioMargin, SurchargeUnits, ScenarioPercentMargin,
> LoadedOverTimeCost, ScenarioHoursWorked, *EmployeeID, Year,
> Week, ProjectNumber, CustomerNumber, ProjectClassID, JobTitle,
> ContractNumber*) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?,
> ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?,
> ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?,
> ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?,
> ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?,
> ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
> bind => [0.0, 0.0, <NONE>, 0.0, <NONE>, 0.0, <NONE>, 0.0,
> <NONE>, 0.0, ANG001, <NONE>, , 0.0, T3, 0.0, 1, 0.0, 0.0, 0.0,
> 0.0, 0.0, null, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, <NONE>,
> 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 60.0, 0.0, 60.0, 0.0, 60.0, 0.0,
> 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, <NONE>, <NONE>, 0.0, <NONE>,
> 0.0, XYZ, 0.0, 2002, 0.0, 0.0, 0.0, 0.0, 0.0, <NONE>, 0.0, 0.0,
> 0.0, 0.0, 0.0, 2.0, Hour, 60.0, 8.0, <NONE>, 8.0, <NONE>, 0.0,
> 64.0, XYZ, 1.43, 0.0, 11.44, 0.0, 91.52, Hour, 0.0, 0.0, 0.0, 9,
> 0.0, 0.0, 151.52, 1.0, 0.0, <NONE>, -151.52, 0.0, 0.0, 0.0, 0.0,
> ANG001, 2002, 1, <NONE>, <NONE>, <NONE>, T3, <NONE>]
>
>
>
>
>
>
> --drg
>
> On Tue, Apr 22, 2008 at 8:32 PM, Marina Vatkina
> <Marina.Vatkina_at_sun.com <mailto:Marina.Vatkina_at_sun.com>
> <mailto:Marina.Vatkina_at_sun.com <mailto:Marina.Vatkina_at_sun.com>>>
> wrote:
>
> Dennis,
>
> Does your @Embeddable contains the same set of
> fields/properties as
> the Entity?
>
> thanks,
> -marina
>
> Dennis Gesker wrote:
>
> Tom:
>
> Thanks for responding back to my email. I put the ms-jdbc
> driver
> configuration (connection pool) back in place and
> increased the
> log levels.
>
> There is no mapping on the entity to other entities. But the
> entity does have an @EmbeddedId decoration and corresponding
> @Embeddable class.
>
> Eight columns do appear twice in the SQL statement that is
> output, all of which are part of the Entities associated
> @Embeddable class.
>
> I commented out the setter method logic but still the
> duplicate
> columns appear. Finally, I commented out the embedded
> field and
> its getter/setter and replaced the embedded field with an
> auto
> generated id field. At this point I was able to persist
> with no
> duplication of columns. (though I now have an unneeded id
> column)
>
> The "table" I'm pulling from is really a query and is
> accessed/setup as an Entity with an EmbeddedId. The table
> into
> which I'm trying to persist entities is almost identical
> to the
> first Entity class -- cut and paste Entity and Embeddable
> class,
> put in new package, put in new persistence unit, allow PU to
> create table in different database.
>
> I didn't anticipate that JPA would add the extra columns
> to the
> INSERT INTO statement (should I have?). I must be doing
> something wrong with the embedded PK but I'm not sure what...
> or, is it supposed to add the columns from EmbeddedId as
> extra
> columns. If so, why didn't these fields get added when JPA
> created the table in the database (assuming the database
> could
> handle duplicate column names) or error out?
>
> Again, I know I'm missing something obvious but I'm not
> sure what...
>
> Dennis
>
>
>
> On Tue, Apr 22, 2008 at 1:11 PM, Tom Ware
> <tom.ware_at_oracle.com <mailto:tom.ware_at_oracle.com>
> <mailto:tom.ware_at_oracle.com <mailto:tom.ware_at_oracle.com>>
> <mailto:tom.ware_at_oracle.com <mailto:tom.ware_at_oracle.com>
>
> <mailto:tom.ware_at_oracle.com
> <mailto:tom.ware_at_oracle.com>>>> wrote:
>
> The first thing to do is to take a look at the SQL
> that is being
> generated. To do that, set your logging to a level that
> allows you
> to see SQL and take a look at the logs. I suggest the
> FINEST
> level
> of logging when debugging. To use that logging level,
> just
> add this
> property to your persistence unit:
>
> <property name="toplink.logging.level" value="FINEST"/>
>
> Looking at the SQL may give you an idea of what is
> happening.
>
> If that doesn't help, please post the SQL, the query
> you are
> running
> and how the entities involved in the query are mapped.
>
> -Tom
>
> Dennis Gesker wrote:
>
> I posted this question to the
> users_at_glassfish.dev.java.net
> <mailto:users_at_glassfish.dev.java.net>
> <mailto:users_at_glassfish.dev.java.net
> <mailto:users_at_glassfish.dev.java.net>>
> <mailto:users_at_glassfish.dev.java.net
> <mailto:users_at_glassfish.dev.java.net>
> <mailto:users_at_glassfish.dev.java.net
> <mailto:users_at_glassfish.dev.java.net>>>
> <mailto:users_at_glassfish.dev.java.net
> <mailto:users_at_glassfish.dev.java.net>
> <mailto:users_at_glassfish.dev.java.net
> <mailto:users_at_glassfish.dev.java.net>>
> <mailto:users_at_glassfish.dev.java.net
> <mailto:users_at_glassfish.dev.java.net>
> <mailto:users_at_glassfish.dev.java.net
> <mailto:users_at_glassfish.dev.java.net>>>> mailing list but didn't
> get a response. In the mean time I swapped out the
> microsoft
> jdbc driver for the jTDS jdbc driver. Still the
> problem
> remains.
>
>
> Exception [TOPLINK-4002] (Oracle TopLink
> Essentials - 2.0.1
> (Build b04-fcs (04/11/2008))):
> oracle.toplink.essentials.exceptions.DatabaseException
> Internal Exception: java.sql.SQLException: Column name
> 'EmployeeID' appears more than once in the result
> column
> list.
> Error Code: 264
>
>
> Any chance of a pointer in the right direction?
>
>
> --drg
>
>
> On Fri, Apr 18, 2008 at 5:00 PM, Dennis Gesker
> <dennis_at_gesker.com <mailto:dennis_at_gesker.com>
> <mailto:dennis_at_gesker.com <mailto:dennis_at_gesker.com>>
> <mailto:dennis_at_gesker.com <mailto:dennis_at_gesker.com>
> <mailto:dennis_at_gesker.com <mailto:dennis_at_gesker.com>>>
> <mailto:dennis_at_gesker.com
> <mailto:dennis_at_gesker.com> <mailto:dennis_at_gesker.com
> <mailto:dennis_at_gesker.com>>
> <mailto:dennis_at_gesker.com <mailto:dennis_at_gesker.com>
> <mailto:dennis_at_gesker.com <mailto:dennis_at_gesker.com>>>>> wrote:
>
> I am trying to use an em to insert data into a
> database table but
> seem to have hit a snag.
>
> The table was created in the database by JPA
> from the
> Entity
> Class
> by setting the toplink.ddl-generation property to
> 'create-tables' in
> the persistence unit.
>
> The field that is being reported as "appearing
> more than
> once" only
> appears once in the Entity class and does have
> both a
> getter and
> setter method -- no compile error. A query
> against the
> syscolums
> table in the database server indicates that the
> field only
> appears
> once. A 'select *' against the table at the
> database
> server also
> only returns this column once.The user/passwd
> combination used in
> the connection pool has full privilages on the
> database.
>
> There are quite a few fields in the table but
> all are
> of basic
> types; string, float, etc. - no blobs; The table is
> meant to be
> updated each evening from a the results of a
> query on
> a different
> database server so presently I'm pulling the data
> (using JPA)
> into a
> resultlist and attempting to use an
> iterator/while loop to
> persist
> the records. The loop doesn't appear to be the
> issue.
>
> The specific error I'm getting is:
>
> Caused by: javax.persistence.PersistenceException:
> Exception
> [TOPLINK-4002] (Oracle TopLink Essentials - 2.0.1
> (Build b03-fcs
> (04/05/2008))):
> oracle.toplink.essentials.exceptions.DatabaseException
> Internal Exception:
> com.microsoft.sqlserver.jdbc.SQLServerException:
> Column name 'EmployeeID' appears more than once
> in the
> result
> column
> list.
>
> The 'Call" portion of the error message
> includes the
> column
> as part
> of the INSERT INTO twice. Other columns are also
> listed twice in
> this statement.
>
>
> Could someone offer a pointer on where I might look
> next to
> resolve
> this item? Any tips or hints would be most
> appreciated.
>
> Dennis
> Using NB6.1, Glassfish V2Ur2
>
>
>
>
> -- Dennis R. Gesker
> email: dennis_at_gesker.com
> <mailto:dennis_at_gesker.com> <mailto:dennis_at_gesker.com
> <mailto:dennis_at_gesker.com>>
> <mailto:dennis_at_gesker.com <mailto:dennis_at_gesker.com>
> <mailto:dennis_at_gesker.com <mailto:dennis_at_gesker.com>>>
> <mailto:dennis_at_gesker.com
> <mailto:dennis_at_gesker.com> <mailto:dennis_at_gesker.com
> <mailto:dennis_at_gesker.com>>
> <mailto:dennis_at_gesker.com <mailto:dennis_at_gesker.com>
> <mailto:dennis_at_gesker.com <mailto:dennis_at_gesker.com>>>>
>
>
> Key Id: 0xEFA10A51
> First things first, but not necessarily in that
> order. --
> Unknown
>
>
>
>
> -- Dennis R. Gesker
> email: dennis_at_gesker.com <mailto:dennis_at_gesker.com>
> <mailto:dennis_at_gesker.com <mailto:dennis_at_gesker.com>>
> <mailto:dennis_at_gesker.com <mailto:dennis_at_gesker.com>
> <mailto:dennis_at_gesker.com <mailto:dennis_at_gesker.com>>>
> Key Id: 0xEFA10A51
> First things first, but not necessarily in that order. --
> Unknown
>
>
>
>
>
> --
> Dennis R. Gesker
> email: dennis_at_gesker.com <mailto:dennis_at_gesker.com>
> <mailto:dennis_at_gesker.com <mailto:dennis_at_gesker.com>>
> Key Id: 0xEFA10A51
> First things first, but not necessarily in that order. -- Unknown
>
>
>
>
>
> --
> Dennis R. Gesker
> email: dennis_at_gesker.com <mailto:dennis_at_gesker.com>
> Key Id: 0xEFA10A51
> First things first, but not necessarily in that order. -- Unknown