2

I use a code generator which generates a nested class, roughly as follows:

package generated;

@Entity(name = "Items")
@Table(name = "ITEMS")
@Inheritance(strategy = InheritanceType.JOINED)
public class Items
    implements Equals, HashCode
{

    protected List<Items.Item> item;

    @OneToMany(targetEntity = Items.Item.class, cascade = {
        CascadeType.ALL
    })
    @JoinColumn(name = "ITEM_ITEMS_HJID")
    public List<Items.Item> getItem() {
        if (item == null) {
            item = new ArrayList<Items.Item>();
        }
        return this.item;
    }

    public void setItem(List<Items.Item> item) {
        this.item = item;
    }

    // ...

    @Entity(name = "Items$Item")
    @Table(name = "ITEM")
    @Inheritance(strategy = InheritanceType.JOINED)
    public static class Item
        implements Equals, HashCode
    {
        // ...        
    }
}

Full source code.

I'm getting the following error in Eclipse:

The Java class for mapped type "Items$Item" is a member class

The error is marked on the @Entity(name = "Items$Item") line.

What does this error mean and what can I do about it?

My roundtrip tests (save entity to the database, load, compare to the original) work just fine.

lexicore
  • 42,748
  • 17
  • 132
  • 221

1 Answers1

1

I actually had a similar issue and found the solution here: The JPA Spec says that mapped member classes are not officially supported. Therefore, Eclipse complains that the class Itemis defined within Items.

Since the code works with the JPA implementation you are using, you can turn off the error message in Eclipse: Window -> Preferences -> Java Persistence -> JPA -> Errors/Warnings -> Type -> Mapped Java class is a member class.

Your code generator does not comply with the JPA specification.

SteffenJacobs
  • 402
  • 2
  • 10