Duplicate NamedQuery generated for Entity with compound primary key

44 views
Skip to first unread message

ggran...@gmail.com

unread,
Aug 29, 2016, 1:02:46 PM8/29/16
to minuteproject
Hi Florian,

I'm seeing duplicate NamedQuery annotations being generated for an entity.  I suspect it has to do with the compound primary key but I'm not certain.

The Ear install fails (using JBoss) with the error:

Caused by: org.hibernate.DuplicateMappingException: Duplicate query mapping DrillTargetTargetizedColor.findByColorNameContaining
at org.hibernate.cfg.Configuration$MappingsImpl.checkQueryName(Configuration.java:2996)
at org.hibernate.cfg.Configuration$MappingsImpl.applyQuery(Configuration.java:2990)

The generated code looks like this (note the duplication):

@Entity (name="DrillTargetTargetizedColor")
@Table (name="\"DrillTargetTargetizedColor\"")
@NamedQueries ({
@NamedQuery(name="DrillTargetTargetizedColor.findAll", query="SELECT a FROM DrillTargetTargetizedColor a")
,@NamedQuery(name="DrillTargetTargetizedColor.findByColorValue", query="SELECT a FROM DrillTargetTargetizedColor a WHERE a.colorValue = :colorValue")
,@NamedQuery(name="DrillTargetTargetizedColor.findByColorNameContaining", query="SELECT a FROM DrillTargetTargetizedColor a WHERE a.colorName_ like :colorName")
,@NamedQuery(name="DrillTargetTargetizedColor.findByDrillTargetImageIdContaining", query="SELECT a FROM DrillTargetTargetizedColor a WHERE a.drillTargetImageId_ like :drillTargetImageId")

,@NamedQuery(name="DrillTargetTargetizedColor.findByHealthValue", query="SELECT a FROM DrillTargetTargetizedColor a WHERE a.healthValue = :healthValue")

,@NamedQuery(name="DrillTargetTargetizedColor.findByPointValue", query="SELECT a FROM DrillTargetTargetizedColor a WHERE a.pointValue = :pointValue")
,@NamedQuery(name="DrillTargetTargetizedColor.findByColorNameContaining", query="SELECT a FROM DrillTargetTargetizedColor a WHERE a.colorName_ like :colorName")
,@NamedQuery(name="DrillTargetTargetizedColor.findByDrillTargetImageIdContaining", query="SELECT a FROM DrillTargetTargetizedColor a WHERE a.drillTargetImageId_ like :drillTargetImageId")

Here is SQL that defines the table in question:

CREATE TABLE [dbo].[DrillTargetTargetizedColor](
[DrillTargetTargetizedColorId] [int] NOT NULL,
[ColorName] [varchar](32) NOT NULL,
[DrillTargetImageId] [int] NOT NULL,
[ColorValue] [int] NOT NULL,
[HealthValue] [int] NOT NULL,
[PointValue] [int] NOT NULL,
[Penalty] [bit] NOT NULL,
[Abort] [bit] NOT NULL,
[CreatedDate] [datetime] NOT NULL,
[ModifiedDate] [datetime] NOT NULL,
[CreatedBy] [varchar](32) NOT NULL,
[ModifiedBy] [varchar](32) NOT NULL,
[LockVersion] [int] NOT NULL,
 CONSTRAINT [DrillTargetTargetizedColor_PK] PRIMARY KEY CLUSTERED 
(
[ColorName] ASC,
[DrillTargetImageId] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]


I'm working around the issue right now by eliminating the compound primary key but I thought you would like to know.

Regards and Thanks,
-Greg

ggran...@gmail.com

unread,
Jan 31, 2017, 1:10:32 PM1/31/17
to minuteproject
Hi Florian,

I'm still getting these duplicate query entries in my code generation.  They do not cause compiler issues but they cause the EAR install to fail.  Any status on this issue?

Florian Adler

unread,
Feb 9, 2017, 9:42:54 AM2/9/17
to minute...@googlegroups.com
Hello Greg,

Thank you in fact, this is a bug,

I think it comes for the fact that ColorName and DrillTargetImageId are part of the pk and it generates one extra query for each composite PK column that are not foreign keys.

I'll fix it,

Best regards,

Florian.


--
Vous recevez ce message, car vous êtes abonné au groupe Google Groupes "minuteproject".
Pour vous désabonner de ce groupe et ne plus recevoir d'e-mails le concernant, envoyez un e-mail à l'adresse minuteproject+unsubscribe@googlegroups.com.
Pour obtenir davantage d'options, consultez la page https://groups.google.com/d/optout.

Florian Adler

unread,
Feb 10, 2017, 3:53:57 AM2/10/17
to minute...@googlegroups.com
Hello Greg,

Before the next release, could you try this patch:

Comment the line 62
,@NamedQuery(name="${className}.findBy${columnClass}Containing", query="$selectChunk WHERE ${nqVar}.${columnVar}_ like :$columnVar")

with
## ,@NamedQuery(name="${className}.findBy${columnClass}Containing", query="$selectChunk WHERE ${nqVar}.${columnVar}_ like :$columnVar")

on the file DomainEntityJPA2Annotation.vm

Best regards,

Florian.

ggran...@gmail.com

unread,
Feb 11, 2017, 6:32:24 PM2/11/17
to minuteproject
The patch seemed to work.  Thanks much.
Pour vous désabonner de ce groupe et ne plus recevoir d'e-mails le concernant, envoyez un e-mail à l'adresse minuteprojec...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages