[jboss-jira] [JBoss JIRA] (WFLY-6377) Composite Keys -- org.hibernate.property.access.spi.PropertyAccessException: Error accessing field
Akhbar Falafel (JIRA)
issues at jboss.org
Wed Mar 16 10:26:00 EDT 2016
[ https://issues.jboss.org/browse/WFLY-6377?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13177869#comment-13177869 ]
Akhbar Falafel commented on WFLY-6377:
--------------------------------------
[~smarlow] HHH-10618
To recreate the issue, I started the Wildfly server with no deployments via Eclipse. Once started, I deployed my .WAR file. At this point, my code _IS_ able to work as expected. Then, I performed a _clean_ (again via Eclipse) to redeploy my .WAR file. Once I do that, I get the exception noted in the report. I will post TRACE logs shortly.
> Composite Keys -- org.hibernate.property.access.spi.PropertyAccessException: Error accessing field
> --------------------------------------------------------------------------------------------------
>
> Key: WFLY-6377
> URL: https://issues.jboss.org/browse/WFLY-6377
> Project: WildFly
> Issue Type: Bug
> Components: JPA / Hibernate
> Affects Versions: 10.0.0.Final
> Environment: Mac OSX, Wildfly 10.0, Hibernate 5.0/5.1, PostgreSQL 9.3
> Reporter: Akhbar Falafel
> Assignee: Scott Marlow
>
> I have 2 entity classes mapped in Hibernate 5.1: ProductBean and CommentBean. They are pretty simple, and look something like this...
> {code:java}
> @Entity(name = "Comment")
> @Table(name = "tbl_comment")
> public class CommentBean implements Serializable {
> @Id
> @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "seq_comment_id")
> @SequenceGenerator(name = "seq_comment_id", sequenceName = "seq_comment_id", allocationSize = 1)
> private Long id = null;
> ...
> }
> @Entity(name = "Product")
> @Table(name = "tbl_product")
> public class CommentBean implements Serializable {
> @Id
> @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "seq_product_id")
> @SequenceGenerator(name = "seq_product_id", sequenceName = "seq_product_id", allocationSize = 1)
> private Long id = null;
> @ManyToMany(cascade = CascadeType.MERGE)
> @JoinTable(name = "tbl_product_comments", joinColumns = {
> @JoinColumn(name = "product_id", referencedColumnName = "id") }, inverseJoinColumns = {
> @JoinColumn(name = "comment_id", referencedColumnName = "id") }, uniqueConstraints = {
> @UniqueConstraint(columnNames = { "product_id", "comment_id" }) })
> @IndexedEmbedded
> @OrderBy(value = "createdDate ASC")
> private Set<CommentBean> comments = new LinkedHashSet<>();
> ...
> }
> {code}
> I'm trying to map the Many-To-Many relation for the comments property in its own class, so that I can add additional properties to the relation in the future. The mapping class looks like this:
> {code:java}
> @Entity(name = "ProductComment")
> @Table(name = "tbl_product_comments")
> public class ProductCommentBean implements Serializable {
> private static final long serialVersionUID = 4730115318809856150L;
> @ManyToOne(optional = false)
> @JoinColumn(name = "productID", referencedColumnName = "id", nullable = false, insertable = false, updatable = false)
> @NotNull
> private ProductBean answer = null;
> @ManyToOne(optional = false)
> @JoinColumn(name = "comment_id", referencedColumnName = "id", nullable = false, insertable = false, updatable = false)
> @NotNull
> private CommentBean comment = null;
> @EmbeddedId
> private ID id = new ID();
> @Embeddable
> public static class ID implements Serializable {
> @Column(name = "product_id")
> private Long productID = null;
> @Column(name = "comment_id")
> private Long commentID = null;
> @Override
> public boolean equals(final Object other) {
> if (this == other) {
> return true;
> }
> if (!(other instanceof ID)) {
> return false;
> }
> ID castOther = (ID) other;
> return new EqualsBuilder().append(productID, castOther. productID).append(commentID, castOther.commentID)
> .isEquals();
> }
> @Override
> public int hashCode() {
> return new HashCodeBuilder(-2081682373, -1619249).append(productID).append(commentID).toHashCode();
> }
> public ID() {
> super();
> // TODO Auto-generated constructor stub
> }
> public ID(Long productID, Long commentID) {
> super();
> this.productID = productID;
> this.commentID = commentID;
> }
> }
> public ProductCommentBean(ProductBean product, CommentBean comment) {
> super();
> this.product = product;
> this.comment = comment;
> this.id.productID =product.getId();
> this.id.commentID = comment.getId();
> }
> }
> ...
> }
> {code}
> Upon my first deployment, I am able to create a ProductCommentBean object and save it to the database successfully. However, if I run a "clean" during development, the subsequent call to save a ProductCommentBean object results in the following exception:
> ISPN000136: Error executing command GetKeyValueCommand, writing keys []: org.hibernate.property.access.spi.PropertyAccessException: Error accessing field [private java.lang.Long com.test.ProductCommentBean$ID.productID] by reflection for persistent property [com.test.ProductCommentBean$ID#productID] : com.test.ProductCommentBean$ID at a8a90e31
> If I do a shutdown and restart of the server, I am once again able to save a ProductCommentBean object the first time. A clean again, however, will set it back to the error state.
> I have tested this code on Wildfly 10 and JBoss EAP 7.0 Beta, and receive the same results. I've also tested it using Hibernate 5.0 and 5.1, also with the same results.
--
This message was sent by Atlassian JIRA
(v6.4.11#64026)
More information about the jboss-jira
mailing list