Hello,
I have a application running on Jboss AS 4.2.2 that uses entities with enum
attributes. I noticed an occurrence while stepping through a method that got me
curious. After a get/set of an enum value from one entity to the other, the
object being set contained the same null value it previously held. No exception
was throw nor debug log printed. The entity getting from had an annotation for
that field that stated @Enumerated(EnumType.STRING) while the entity being set
did not have this annotation. However, as expected, an exception was
encountered when the entity, that was set, was committed to the database.
I don't understand why the value was not transferred, or at least why no
exception was thrown or error logged.
Here is some code to illustrate:
|
| public enum ColorEnum {
| BLONDE("Blonde"),
| RED("Red"),
| TAN("Tan");
| }
|
| @Entity
| @Table(name = "DOG")
| public class Dog {
| @Column(name = "COAT_COLOR"
| @Enumerated(EnumType.STRING)
| ColorEnum coatColor;
|
| public void setCoatColor(ColorEnum coatColor) {
| this.coatColor = coatColor;
| }
|
| public ColorEnumgetCoatColor() { return this.coatColor; }
| }
|
| @Entity
| @Table(name = "CAT")
| public class Cat {
| @Column(name = "COAT_COLOR"
| ColorEnum coatColor;
|
| public void setCoatColor(ColorEnum coatColor) {
| this.coatColor = coatColor;
| }
|
| public ColorEnumgetCoatColor() { return this.coatColor; }
| }
|
|
| public void newCatWithDogCoat() {
| ...
| // cat.getCoatColor() returns null
| // dog.getCoatColor() returns red
| cat.setCoatColor(dog.getCoatColor());
| ...
| // cat.getCoatColor() still returns null (no errors/exceptions)
| }
|
After adding @Enumerated(EnumType.STRING) to the Cat class, cat.getCoatColor()
returns red
So why are there no exceptions/errors until it fails to save to the database?
View the original post :
http://www.jboss.org/index.html?module=bb&op=viewtopic&p=4215533#4215533
Reply to the post :
http://www.jboss.org/index.html?module=bb&op=posting&mode=reply&p=4215533
_______________________________________________
jboss-user mailing list
[email protected]
https://lists.jboss.org/mailman/listinfo/jboss-user