Uploaded image for project: 'WildFly'
  1. WildFly
  2. WFLY-6377

Composite Keys -- org.hibernate.property.access.spi.PropertyAccessException: Error accessing field

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed (View Workflow)
    • Priority: Major
    • Resolution: Done
    • Affects Version/s: 10.0.0.Final
    • Fix Version/s: 10.1.0.CR1, 10.1.0.Final
    • Component/s: JPA / Hibernate
    • Labels:
      None
    • Environment:

      Mac OSX, Wildfly 10.0, Hibernate 5.0/5.1, PostgreSQL 9.3

      Description

      I have 2 entity classes mapped in Hibernate 5.1: ProductBean and CommentBean. They are pretty simple, and look something like this...

      @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<>();
      
        ...
      }
      

      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:

      @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();
                   }
      	}
      
        ...
      }
      

      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@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.

        Gliffy Diagrams

          Attachments

            Activity

              People

              • Assignee:
                smarlow Scott Marlow
                Reporter:
                sdnakhla Akhbar Falafel
              • Votes:
                0 Vote for this issue
                Watchers:
                4 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: