Bug 333656 - Map<String, AbstractEntity> mapping throws InstantiationException
Summary: Map<String, AbstractEntity> mapping throws InstantiationException
Status: NEW
Alias: None
Product: z_Archived
Classification: Eclipse Foundation
Component: Eclipselink (show other bugs)
Version: unspecified   Edit
Hardware: PC Windows XP
: P2 blocker (vote)
Target Milestone: ---   Edit
Assignee: Nobody - feel free to take it CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-01-06 09:43 EST by michok34 CLA
Modified: 2022-06-09 10:31 EDT (History)
3 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description michok34 CLA 2011-01-06 09:43:31 EST
Always reproducible.

Case :

@Entity
class ShoppingCart implements Serializable {
  @Id
  private String ID;
  
  @OneToMany(cascade = { CascadeType.ALL, CascadeType.REMOVE },
			   orphanRemoval = true, mappedBy = "cart")
  @MapKey(name = "keyref")
  private Map<String, Item> items = new HashMap<String, Item>();
  // Getters, Setters...
}

@Entity
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(discriminatorType = DiscriminatorType.STRING, name = "type")
public abstract class Item implements Serializable {

  @Id
  private String ID;

  private String keyref;

  @ManyToOne
  @JoinColumn(name = "cart_ID", referencedColumnName = "ID")
  private ShoppingCart cart;
  // Getters, Setters...
}


@Entity
@DiscriminatorValue(value = "ConcreteItem")
public class ConcreteItem extends Item {
  ...
}

class SessionMgr {

  public void save(ShoppingCart cart) {
    ...
    EntityTransaction transaction = entitymanager.getTransaction();
    ...
    transaction.begin();
    entitymanager.persist(cart);
    transaction.commit();
  }

}

On commit the produced Stacktrace is:

javax.persistence.RollbackException: Exception [EclipseLink-34] (Eclipse Persistence Services - 2.0.1.v20100213-r6600): org.eclipse.persistence.exceptions.DescriptorException
Exception Description: This class does not define a public default constructor, or the constructor raised an exception.
Internal Exception: java.lang.InstantiationException
Descriptor: RelationalDescriptor(com.blah.Item --> [DatabaseTable(item)])
	at org.eclipse.persistence.internal.jpa.transaction.EntityTransactionImpl.commitInternal(EntityTransactionImpl.java:102)
	at org.eclipse.persistence.internal.jpa.transaction.EntityTransactionImpl.commit(EntityTransactionImpl.java:63)
	at com.blah.SessionMgr.save(SessionMgr.java:...)



However, if I modify my ShoppingCart like this:

@Entity
class ShoppingCart implements Serializable {
  @Id
  private String ID;
  
  @OneToMany(cascade = { CascadeType.ALL, CascadeType.REMOVE },
			   orphanRemoval = true, mappedBy = "cart")
  private List<Item> items = new ArrayList<Item>();

  // Getters, Setters...
}

There's no issue
Comment 1 michok34 CLA 2011-01-06 11:39:31 EST
previous case modification to reproduce:

@MappedSuperClass
class Cart implements Serializable {
  @Id
  private String ID;
  // Getters, Setters...
}

@Entity
class ShoppingCart extends Cart {

  @OneToMany(cascade = { CascadeType.ALL, CascadeType.REMOVE },
               orphanRemoval = true, mappedBy = "cart")
  @MapKey(name = "key")
  private Map<String, Item> items = new HashMap<String, Item>();
  // Getters, Setters...
}

@Entity
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(discriminatorType = DiscriminatorType.STRING, name =
"type")
public abstract class Item implements Serializable {

  @Id
  private String ID;

  private String key;

  @ManyToOne
  @JoinColumn(name = "cart_ID", referencedColumnName = "ID")
  private ShoppingCart cart;
  // Getters, Setters...
}


It seems that changing MapKey from "key" to "keyref" solves the problem...
Comment 2 Tom Ware CLA 2011-01-07 13:36:03 EST
It is not clear to me which of the cases you have posted reproduces the problem, the one in the initial post, the one in the second post, or both.  Can you please clarify.  Can you please also clarify your comment about "key" vs. "keyref".
Comment 3 Tom Ware CLA 2011-01-13 11:19:36 EST
Setting target and priority.  See the following page for the meanings of these fields:

http://wiki.eclipse.org/EclipseLink/Development/Bugs/Guidelines

Still awaiting information requested above.
Comment 4 Eclipse Webmaster CLA 2022-06-09 10:31:57 EDT
The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink