Home » Eclipse Projects » Dali » Generate Entities not adding @Table or @Column annotations
|
Re: Generate Entities not adding @Table or @Column annotations [message #435460 is a reply to message #435459] |
Thu, 12 February 2009 23:21 |
Neil Hauge 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 #435464 is a reply to message #435462] |
Mon, 16 February 2009 14:59 |
Neil Hauge 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 |
Neil Hauge 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 #614915 is a reply to message #435462] |
Mon, 16 February 2009 14:59 |
Neil Hauge 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
|
|
|
Goto Forum:
Current Time: Wed Sep 18 21:16:56 GMT 2024
Powered by FUDForum. Page generated in 0.03525 seconds
|