code generation problem: variable [id] is already defined in class #861

Closed
yeradis opened this Issue Jul 20, 2014 · 3 comments

Comments

Projects
None yet
2 participants
@yeradis

yeradis commented Jul 20, 2014

There is a problem with code generation from schema, in this case when there is a table field name that has the same name that the PK, but i suppose that this can happen with others too.

Table DDL:

CREATE TABLE [dbo].[HOTEL_TIPO_HAB_OVERBOOKING](
    [ID] [int] IDENTITY(1,1) NOT NULL,
    [FK_ID_HOTEL_MOVERBOOKING] [int] NOT NULL,
    [FK_CODIGOHOT] [varchar](3) NOT NULL,
    [FK_CODTIPOHAB] [varchar](6) NOT NULL,
    [CANTIDAD] [int] NOT NULL,
    [FECHA] [datetime] NOT NULL,
 CONSTRAINT [ID] PRIMARY KEY NONCLUSTERED 
(
    [ID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO

SET ANSI_PADDING OFF
GO

ALTER TABLE [dbo].[HOTEL_TIPO_HAB_OVERBOOKING]  WITH NOCHECK ADD  CONSTRAINT [FK_HOTEL_TIPO_HAB_OVERBOOKING_HOTEL_MOVERBOOKING] FOREIGN KEY([FK_ID_HOTEL_MOVERBOOKING])
REFERENCES [dbo].[HOTEL_MOVERBOOKING] ([ID])
GO

ALTER TABLE [dbo].[HOTEL_TIPO_HAB_OVERBOOKING] CHECK CONSTRAINT [FK_HOTEL_TIPO_HAB_OVERBOOKING_HOTEL_MOVERBOOKING]
GO

ALTER TABLE [dbo].[HOTEL_TIPO_HAB_OVERBOOKING]  WITH NOCHECK ADD  CONSTRAINT [FK_HOTEL_TIPO_HAB_OVERBOOKING_HOTEL_TIPO_HAB] FOREIGN KEY([FK_CODTIPOHAB], [FK_CODIGOHOT])
REFERENCES [dbo].[HOTEL_TIPO_HAB] ([CODTIPOHAB], [FK_CODIGOHOT])
GO

ALTER TABLE [dbo].[HOTEL_TIPO_HAB_OVERBOOKING] CHECK CONSTRAINT [FK_HOTEL_TIPO_HAB_OVERBOOKING_HOTEL_TIPO_HAB]
GO

Generated Querydsl query type for HotelTipoHabOverbooking

@Generated("com.mysema.query.sql.codegen.MetaDataSerializer")
public class QHotelTipoHabOverbooking extends com.mysema.query.sql.RelationalPathBase<HotelTipoHabOverbooking> {

    private static final long serialVersionUID = -1385408739;

    public static final QHotelTipoHabOverbooking hotelTipoHabOverbooking = new QHotelTipoHabOverbooking("HOTEL_TIPO_HAB_OVERBOOKING");

    public final NumberPath<Integer> cantidad = createNumber("cantidad", Integer.class);

    public final DateTimePath<java.sql.Timestamp> fecha = createDateTime("fecha", java.sql.Timestamp.class);

    public final StringPath fkCodigohot = createString("fkCodigohot");

    public final StringPath fkCodtipohab = createString("fkCodtipohab");

    public final NumberPath<Integer> fkIdHotelMoverbooking = createNumber("fkIdHotelMoverbooking", Integer.class);

    public final NumberPath<Integer> id = createNumber("id", Integer.class);

    public final com.mysema.query.sql.PrimaryKey<HotelTipoHabOverbooking> id = createPrimaryKey(id);

    public final com.mysema.query.sql.ForeignKey<HotelMoverbooking> hotelTipoHabOverbookingHotelMoverbookingFk = createForeignKey(fkIdHotelMoverbooking, "ID");

    public final com.mysema.query.sql.ForeignKey<HotelTipoHab> hotelTipoHabOverbookingHotelTipoHabFk = createForeignKey(Arrays.asList(fkCodtipohab, fkCodigohot), Arrays.asList("CODTIPOHAB", "FK_CODIGOHOT"));

    public QHotelTipoHabOverbooking(String variable) {
        super(HotelTipoHabOverbooking.class, forVariable(variable), "dbo", "HOTEL_TIPO_HAB_OVERBOOKING");
        addMetadata();
    }

    public QHotelTipoHabOverbooking(String variable, String schema, String table) {
        super(HotelTipoHabOverbooking.class, forVariable(variable), schema, table);
        addMetadata();
    }

    public QHotelTipoHabOverbooking(Path<? extends HotelTipoHabOverbooking> path) {
        super(path.getType(), path.getMetadata(), "dbo", "HOTEL_TIPO_HAB_OVERBOOKING");
        addMetadata();
    }

    public QHotelTipoHabOverbooking(PathMetadata<?> metadata) {
        super(HotelTipoHabOverbooking.class, metadata, "dbo", "HOTEL_TIPO_HAB_OVERBOOKING");
        addMetadata();
    }

    public void addMetadata() {
        addMetadata(cantidad, ColumnMetadata.named("CANTIDAD").withIndex(5).ofType(4).withSize(10).notNull());
        addMetadata(fecha, ColumnMetadata.named("FECHA").withIndex(6).ofType(93).withSize(23).withDigits(3).notNull());
        addMetadata(fkCodigohot, ColumnMetadata.named("FK_CODIGOHOT").withIndex(3).ofType(12).withSize(3).notNull());
        addMetadata(fkCodtipohab, ColumnMetadata.named("FK_CODTIPOHAB").withIndex(4).ofType(12).withSize(6).notNull());
        addMetadata(fkIdHotelMoverbooking, ColumnMetadata.named("FK_ID_HOTEL_MOVERBOOKING").withIndex(2).ofType(4).withSize(10).notNull());
        addMetadata(id, ColumnMetadata.named("ID").withIndex(1).ofType(4).withSize(10).notNull());
    }

}

The problem in that code:

public final NumberPath<Integer> id = createNumber("id", Integer.class);
public final com.mysema.query.sql.PrimaryKey<HotelTipoHabOverbooking> id = createPrimaryKey(id);

I´m using the maven plugin for the code generation, shows something like:

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on project . . .
[ERROR] . . . /QHotelTipoHabOverbooking.java:[40,75] variable id is already defined in class QHotelTipoHabOverbooking

I know this can be easily fixed just using a proper name for that constraint, but changing the database is not and option, is a production version :S

@timowest

This comment has been minimized.

Show comment
Hide comment
@timowest

timowest Jul 20, 2014

Member

Thanks for the bug report. I added a pull request with a fix.

Member

timowest commented Jul 20, 2014

Thanks for the bug report. I added a pull request with a fix.

@timowest timowest added this to the 3.4.2 milestone Jul 20, 2014

@yeradis

This comment has been minimized.

Show comment
Hide comment
@yeradis

yeradis Jul 20, 2014

Perfect! Thank you very much ;)

yeradis commented Jul 20, 2014

Perfect! Thank you very much ;)

@timowest

This comment has been minimized.

Show comment
Hide comment
@timowest

timowest Jul 29, 2014

Member

Released in 3.4.2

Member

timowest commented Jul 29, 2014

Released in 3.4.2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment