geogaddi
geogaddi

Reputation: 575

java.lang.IllegalStateException : Attempting Create Multiple Associations On Variables of Class

first post here, hoping someone could perhaps shed some light on an issue I've been trying to juggle...

As a part of a school project we're attempting to build a interface to display points on a map and paths on a map.

For our first sprint I managed to work out storing/retrieving items using Objectify - it went great!

Now we're trying to extend the functionality for our next spring. Having problems now trying to store an object of type MapPath (note MapPath and MapData, our two data types, both extend class Data). Brief code snippets as follows :

    @Entity
    public class Data extends JavaScriptObject
    {
        @Id
        Long id;
        private String name;
        private String dataSet;

     ...getters and setters
    }

    @Subclass
    public class MapData extends Data implements Serializable{
    {
        private String name;
        private String address;
        private String dataSet;
        @Embedded
        private Coordinate location;

            ....constructors, getters/setters
    }

    @Subclass
    public class PathData extends Data implements Serializable{

        private String name;
        private String address;
        private String dataSet;
        @Embedded
        private Coordinate[] path;

            ...etc
    }

Now hopefully I haven't lost you yet. I have a DataService class that basically handles all transactions. I have the following unit test :

    @Test
    public void storeOnePath(){
        PathData pd = new PathData();
        pd.setName("hi");
        DataService.storeSingleton(pd);

        Data d = DataService.getSingleton("hi");

        assertEquals(pd,d);
    }    

The implementation of getSingleton is as follows :

    public static void storeSingleton(Data d){
        Objectify obj = ObjectifyService.begin();
        obj.put(d);
}

JUnit complains:

java.lang.ExceptionInInitializerError
    at com.teamrawket.tests.DataTest.storeOnePath(DataTest.java:59)
        ...<taken out>
Caused by: java.lang.IllegalStateException: Attempting to create multiple associations on class com.teamrawket.server.MapData for name
    at com.googlecode.objectify.impl.Transmog$Visitor.addRootSetter(Transmog.java:298)
    at com.googlecode.objectify.impl.Transmog$Visitor.visitField(Transmog.java:231)
    at com.googlecode.objectify.impl.Transmog$Visitor.visitClass(Transmog.java:134)
    at com.googlecode.objectify.impl.Transmog.<init>(Transmog.java:319)
    at com.googlecode.objectify.impl.ConcreteEntityMetadata.<init>(ConcreteEntityMetadata.java:75)
    at com.googlecode.objectify.impl.Registrar.registerPolymorphicHierarchy(Registrar.java:128)
    at com.googlecode.objectify.impl.Registrar.register(Registrar.java:62)
    at com.googlecode.objectify.ObjectifyFactory.register(ObjectifyFactory.java:209)
    at com.googlecode.objectify.ObjectifyService.register(ObjectifyService.java:38)
    at com.teamrawket.server.DataService.<clinit>(DataService.java:20)
    ... 27 more

What exactly does "attempting to create multiple associations on class ... for name" imply?

Sorry for the long post and any formatting issues that may arise.

Upvotes: 0

Views: 660

Answers (2)

stickfigure
stickfigure

Reputation: 13556

You have repeated field names in your subclasses. You should not declare 'name' and 'dataSet' in both superclasses and subclasses; remove these fields from MapData and PathData and you should be fine.

Upvotes: 1

len
len

Reputation: 335

com.teamrawket.server.MapData refers to the fullPath name for your MapData file. The name at the end refers to the field String name in your MapData class. This whole exception tries to tell you that it already contains a reference for that specific fullPath. I would say there is another object with the same fullPath already registered. It would be helpful to know where line 59 is exactly as that is where the error occured.

Upvotes: 0

Related Questions