Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Dali » Generate Entities not adding @Table or @Column annotations
Generate Entities not adding @Table or @Column annotations [message #435459] Wed, 11 February 2009 20:55 Go to next message
Rick Crawford is currently offline Rick CrawfordFriend
Messages: 6
Registered: July 2009
Junior Member
I'm using Eclipse 3.4.1, trying to generate entities using the JPA wizard
to generate entities from existing tables in our DB2 database. I go thru
all the steps, and get no errors. The entity classes are generated, but
the only JPA annotation that is added is the @Entity annotation. The
@Table, the @Column's, etc. are not added.

The generated classes do have properties for each of the columns in the
table(s), but no @Column annotations. Is this the expected behavior, or
am I missing something?

Thanks!
Rick
Re: Generate Entities not adding @Table or @Column annotations [message #435460 is a reply to message #435459] Thu, 12 February 2009 23:21 Go to previous messageGo to next message
Neil Hauge is currently offline Neil HaugeFriend
Messages: 475
Registered: July 2009
Senior Member
Hi Rick,

This is by design. JPA utilizes a concept referred to as "configuration
by exception", which for JPA basically means that where an object
"matches" a relational schema, there is no need to define the mapping.
These implied mappings are defined by the JPA specification, and a
persistence provider will use these default mappings by default unless you
decide to specify a mapping that overrides it.

For the example you mention, there is a default Column value that is
assumed, in this case being the attribute name. Sine the attribute name
and the table's column name match, there is no need to specify the
@Column. If they didn't match, the Entity Generation would insert @Column
with an appropriate value.

All of these "defaults" are defined in the JPA Spec. If you use the Dali
views, you can actually see what the default values are in a given
mapping. Our validation will tell you when the defaults don't work, and
in those cases you will need to override the default mapping. These are a
couple of the ways that Dali makes life easier for JPA development.

Hope this helps,
Neil


Rick Crawford wrote:

> I'm using Eclipse 3.4.1, trying to generate entities using the JPA wizard
> to generate entities from existing tables in our DB2 database. I go thru
> all the steps, and get no errors. The entity classes are generated, but
> the only JPA annotation that is added is the @Entity annotation. The
> @Table, the @Column's, etc. are not added.

> The generated classes do have properties for each of the columns in the
> table(s), but no @Column annotations. Is this the expected behavior, or
> am I missing something?

> Thanks!
> Rick
Re: Generate Entities not adding @Table or @Column annotations [message #435462 is a reply to message #435460] Mon, 16 February 2009 14:49 Go to previous messageGo to next message
Rick Crawford is currently offline Rick CrawfordFriend
Messages: 6
Registered: July 2009
Junior Member
Neil:

Thanks so much for the reply. Based on your remarks, I think I've figured
out what's going on.

Some tables in my schema have underscores in the table name, while others
do not. If there ARE underscores in the table name, the mapper includes
the @Table annotation, and the class name is set to the actual table name
with no underscores.

Most tables in my schema have underscores in the column names. But for
the few columns that don't have underscores, there is no @Column
annotation provided.

Is that the expected behavior? Thanks!!!

Rick
Re: Generate Entities not adding @Table or @Column annotations [message #435464 is a reply to message #435462] Mon, 16 February 2009 14:59 Go to previous message
Neil Hauge is currently offline Neil HaugeFriend
Messages: 475
Registered: July 2009
Senior Member
Rick,

Yes, this is expected. The Entity Generator tries to create decent class
and attribute names, so it removes underscores and converts them to
camelCase for appropriate Java names. When the table or column name
already makes an appropriate class or attribute name, it leaves it alone,
and as a result, no @Table or @Column overrides are necessary.

Neil

Rick Crawford wrote:

> Neil:

> Thanks so much for the reply. Based on your remarks, I think I've figured
> out what's going on.

> Some tables in my schema have underscores in the table name, while others
> do not. If there ARE underscores in the table name, the mapper includes
> the @Table annotation, and the class name is set to the actual table name
> with no underscores.

> Most tables in my schema have underscores in the column names. But for
> the few columns that don't have underscores, there is no @Column
> annotation provided.

> Is that the expected behavior? Thanks!!!

> Rick
Re: Generate Entities not adding @Table or @Column annotations [message #614907 is a reply to message #435459] Thu, 12 February 2009 23:21 Go to previous message
Neil Hauge is currently offline Neil HaugeFriend
Messages: 475
Registered: July 2009
Senior Member
Hi Rick,

This is by design. JPA utilizes a concept referred to as "configuration
by exception", which for JPA basically means that where an object
"matches" a relational schema, there is no need to define the mapping.
These implied mappings are defined by the JPA specification, and a
persistence provider will use these default mappings by default unless you
decide to specify a mapping that overrides it.

For the example you mention, there is a default Column value that is
assumed, in this case being the attribute name. Sine the attribute name
and the table's column name match, there is no need to specify the
@Column. If they didn't match, the Entity Generation would insert @Column
with an appropriate value.

All of these "defaults" are defined in the JPA Spec. If you use the Dali
views, you can actually see what the default values are in a given
mapping. Our validation will tell you when the defaults don't work, and
in those cases you will need to override the default mapping. These are a
couple of the ways that Dali makes life easier for JPA development.

Hope this helps,
Neil


Rick Crawford wrote:

> I'm using Eclipse 3.4.1, trying to generate entities using the JPA wizard
> to generate entities from existing tables in our DB2 database. I go thru
> all the steps, and get no errors. The entity classes are generated, but
> the only JPA annotation that is added is the @Entity annotation. The
> @Table, the @Column's, etc. are not added.

> The generated classes do have properties for each of the columns in the
> table(s), but no @Column annotations. Is this the expected behavior, or
> am I missing something?

> Thanks!
> Rick
Re: Generate Entities not adding @Table or @Column annotations [message #614911 is a reply to message #435460] Mon, 16 February 2009 14:49 Go to previous message
Rick Crawford is currently offline Rick CrawfordFriend
Messages: 6
Registered: July 2009
Junior Member
Neil:

Thanks so much for the reply. Based on your remarks, I think I've figured
out what's going on.

Some tables in my schema have underscores in the table name, while others
do not. If there ARE underscores in the table name, the mapper includes
the @Table annotation, and the class name is set to the actual table name
with no underscores.

Most tables in my schema have underscores in the column names. But for
the few columns that don't have underscores, there is no @Column
annotation provided.

Is that the expected behavior? Thanks!!!

Rick
Re: Generate Entities not adding @Table or @Column annotations [message #614915 is a reply to message #435462] Mon, 16 February 2009 14:59 Go to previous message
Neil Hauge is currently offline Neil HaugeFriend
Messages: 475
Registered: July 2009
Senior Member
Rick,

Yes, this is expected. The Entity Generator tries to create decent class
and attribute names, so it removes underscores and converts them to
camelCase for appropriate Java names. When the table or column name
already makes an appropriate class or attribute name, it leaves it alone,
and as a result, no @Table or @Column overrides are necessary.

Neil

Rick Crawford wrote:

> Neil:

> Thanks so much for the reply. Based on your remarks, I think I've figured
> out what's going on.

> Some tables in my schema have underscores in the table name, while others
> do not. If there ARE underscores in the table name, the mapper includes
> the @Table annotation, and the class name is set to the actual table name
> with no underscores.

> Most tables in my schema have underscores in the column names. But for
> the few columns that don't have underscores, there is no @Column
> annotation provided.

> Is that the expected behavior? Thanks!!!

> Rick
Previous Topic:no JPA implentation information in "modify JPA facet" dialog
Next Topic:Generate Entities from Tables not working
Goto Forum:
  


Current Time: Thu Mar 28 10:12:31 GMT 2024

Powered by FUDForum. Page generated in 0.02729 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top