With nearly two decades of experience working in the IT industry in various roles as Enterprise technology consultant, Java Architect, project leader, Engineer, Designer and Developer, Mr. Knutson has gained a wide variety of experience in disciplines including JavaEE, Web Services, Mobile Computing and Enterprise Integration Solutions. Over the course of his career, Mr. Knutson has enjoyed long lasting partnerships with many of the most recognizable names in the Health Care, Financial, Banking, Insurance, Manufacturing, Telecommunications, Utilities, Product Distribution, Industrial and Electronics industries employing industry standard full software life cycle methodologies including the Rational Unified Process (RUP), Agile, SCRUM, and Extreme Programming (XP). Mr. Knutson has also undertaken speaking engagements, training seminars, white paper and book publishing engagements world-wide. As an active Blogger and tweeter, Mr. Knutson has also been inducted in the prestigious DZone.com Most Valuable Blogger (MVB) group and can be followed at http://www.dzone.com/page/mvbs and twitter at http://twitter.com/mickknutson. Able to quickly and effectively adapt to any phase of an existing project from Business Modeling to Production Support, Mr. Knutson’s wide array of technical expertise in OOA / OOD / OOP, Java, J2EE, Internet, Oracle, Enterprise Integration and Message Oriented Middleware allow him to seamlessly integrate into your Information Systems project at any phase and provide immediate productivity. Mr. Knutson is exceptional at team building and motivating either at a peer-to-peer level, or in a leadership role with excellent communications skills and the ability to adapt to all environments and cultures with ease. Mick is a DZone MVB and is not an employee of DZone and has posted 18 posts at DZone. You can read more from them at their website. View Full User Profile

No Subclass Matches This Class; for This Aggregate Mapping With Inheritance

02.07.2011
| 3745 views |
  • submit to reddit

No subclass matches this class [class com.baselogic.test.CustomerFixture$2$1] for this Aggregate mapping with inheritance. I have been writing a chapter for my new book “Java EE6 Cookbook for Securing, Tuning and Extending Enterprise applications” today, and I ran across an interesting error based on a JPA testing pattern.

I have used 2 patterns for seeding data to test some @CollectionTable functionality.
First, I used DBUnit to seed my data, and that seems to work just fine for adding @CollectionTable relationships.

The second seemed fairly straight forward. I wanted to create a Fixture utility to create an entity to insert

Customer customer = CustomerFixture.createSingleCustomer();

My CustomerFixture.createSingleCustomer() is fairly simple

public static Customer createSingleCustomer() {
Customer customer = new Customer();
customer.setUsername("testusername");
customer.setFirstName("Mick");
customer.setLastName("Knutson");
customer.setDescription("Customer with an Android Device.");
customer.setHobbies(
new HashSet<String>() {{
add("BASE-Jumping");
add("Skydiving");
add("Speed-Flying");
}}
);
customer.setPhones(createPhones());
customer.setAddresses(createAddresses());
return customer;
}

 

I was adding Address’s that looked like this

public static Map<String, Address> createAddresses() {
final int pk = getRandomInt(1, 999);
return new HashMap<String, Address>() {{
put(String.format("%03d", pk),
new Address(){{
setType(AddressType.RESIDENTIAL);
setStreet("123 Main Street");
setCity("San Francisco");
setState("CA");
setPostCode("91335");
setProvince("");
}}
);
}};

Notice that I created the Address with a default constructor…?

When running this, I get a very interesting exception:

javax.persistence.EntityExistsException:
Exception Description: No subclass matches this class [class com.baselogic.test.CustomerFixture$2$1] for this Aggregate mapping with inheritance.
Mapping: org.eclipse.persistence.mappings.AggregateCollectionMapping[addresses]
Descriptor: RelationalDescriptor(com.baselogic.chapter02.Customer --> [DatabaseTable(CUSTOMER)])

What I finally tracked this down to was from skimming the XXX codes on http://wiki.eclipse.org/EclipseLink_Exception_Error_Reference_%28ELUG%29

ECLIPSELINK-00068: The value of an aggregate in object [{0}] is null. Null values not allowed for Aggregate mappings unless “Allow Null” is specified.
Cause: The value of the aggregate in the source object object is null. Null values are not allowed for aggregate mappings unless allow null is specified in the aggregate mapping.
Action: Call the mapping method allowNull. Provide parameters only if you are making a distinction between foo() and foo(integer).

Specifically the ‘Action’.
So I started looking at my Fixture, and constructed my Address with a specific Constructor:

public static Map<String, Address> createAddresses(){
final int pk = getRandomInt(1, 999);
return new HashMap<String, Address>(){{
put(String.format("%03d", pk),
new Address(
AddressType.RESIDENTIAL,
"123 Main Street",
"San Francisco",
"CA",
"94114"
)
);
}};
}

This solved the issue, and the seeding of the Customer succeeded.

From http://www.baselogic.com/blog/development/java-javaee-j2ee/no-subclass-matches-this-class-for-this-aggregate-mapping-with-inheritance

Published at DZone with permission of Mick Knutson, author and DZone MVB.

(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)

Tags: