0

I have an inner class:

@Entity
public class InnerTypes implements Serializable {

    private static final long serialVersionUID = 3839105307661662120L;

    @Id
    public int id;

    public PrimitiveInnerTypes primitiveInnerTypes;

    public PrimitiveInnerTypes getPrimitiveInnerTypes() {
        return primitiveInnerTypes;
    }

    public void setPrimitiveInnerTypes(PrimitiveInnerTypes primitiveInnerTypes) {
        this.primitiveInnerTypes = primitiveInnerTypes;
    }

    @Entity
    public static class PrimitiveInnerTypes implements Serializable {
         //some code ...
    }
}

I have it on my persistence.xml as well

<class>pt.ptinovacao.persistencetester.model.InnerTypes$PrimitiveInnerTypes</class>

By using the $ sign (I think) I get the following exception:

[EL Warning]: Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.4.2.v20130514-5956486): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: java.sql.SQLSyntaxErrorException: unexpected token: INNERTYPES$PRIMITIVEINNERTYPES

I don't know how to fix, if I change the $ sign to a . I can't access the inner class because . is only for different packages. What can I do?

Thanks

Mandar Pandit
  • 2,171
  • 5
  • 36
  • 58
SaintLike
  • 9,119
  • 11
  • 39
  • 69

1 Answers1

3

Paragraph 2.1 of the JPA specifications:

The entity class must be a top-level class.

So you can't use a nested class for an entity. Make it a top-level class.

JB Nizet
  • 678,734
  • 91
  • 1,224
  • 1,255
  • 2
    However given the error (an `SQLException`), I suspect that EclipseLink does allow it, but that the underlying database doesn't allow `$` in its objectnames. In that case the solution would be to add an explicit name. – Mark Rotteveel Jun 17 '14 at 16:49
  • @MarkRotteveel: agreed. But the most appropriate solution IMHO is still to make it a top-level class, to conform to the spec. – JB Nizet Jun 17 '14 at 16:51
  • I don't know if I can change the class and make it a top-level class but, I'll ask around and try to fix this. Thanks all – SaintLike Jun 17 '14 at 16:55