Google AppEngine Key exception












0















I have two classes, CarRentalCompany



@Entity
public class CarRentalCompany {

private static Logger logger = Logger.getLogger(CarRentalCompany.class.getName());

@Id
private String name;

@OneToMany(cascade = CascadeType.ALL)
private List<Car> cars;

@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
private List<CarType> carTypes = new ArrayList<>(); //TODO: kan betere datastructuur zijn

/***************
* CONSTRUCTOR *
***************/

public CarRentalCompany()
{
// DEFAULT CONSTRUCTOR
}

public CarRentalCompany(String name, List<Car> cars) {
logger.log(Level.INFO, "<{0}> Car Rental Company {0} starting up...", name);
setName(name);
this.cars = cars;
for(Car car:cars)
carTypes.add(car.getType());
}
...
}


and CarType



@Entity
public class CarType {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Key key;

private String name;
private int nbOfSeats;
private boolean smokingAllowed;
private double rentalPricePerDay;
//trunk space in liters
private float trunkSpace;

/***************
* CONSTRUCTOR *
***************/

public CarType()
{

}

public CarType(String name, int nbOfSeats, float trunkSpace, double rentalPricePerDay, boolean smokingAllowed) {
this.name = name;
this.nbOfSeats = nbOfSeats;
this.trunkSpace = trunkSpace;
this.rentalPricePerDay = rentalPricePerDay;
this.smokingAllowed = smokingAllowed;
}


When running the application, it throws the following exception:




NucleusFatalUserException: Attempt to assign child with key
"CarType(6614661952700416)" to parent with key
"CarRentalCompany("Hertz")". Parent keys are immutable




What do I need to do to get the key of the CarType right?










share|improve this question





























    0















    I have two classes, CarRentalCompany



    @Entity
    public class CarRentalCompany {

    private static Logger logger = Logger.getLogger(CarRentalCompany.class.getName());

    @Id
    private String name;

    @OneToMany(cascade = CascadeType.ALL)
    private List<Car> cars;

    @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
    private List<CarType> carTypes = new ArrayList<>(); //TODO: kan betere datastructuur zijn

    /***************
    * CONSTRUCTOR *
    ***************/

    public CarRentalCompany()
    {
    // DEFAULT CONSTRUCTOR
    }

    public CarRentalCompany(String name, List<Car> cars) {
    logger.log(Level.INFO, "<{0}> Car Rental Company {0} starting up...", name);
    setName(name);
    this.cars = cars;
    for(Car car:cars)
    carTypes.add(car.getType());
    }
    ...
    }


    and CarType



    @Entity
    public class CarType {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Key key;

    private String name;
    private int nbOfSeats;
    private boolean smokingAllowed;
    private double rentalPricePerDay;
    //trunk space in liters
    private float trunkSpace;

    /***************
    * CONSTRUCTOR *
    ***************/

    public CarType()
    {

    }

    public CarType(String name, int nbOfSeats, float trunkSpace, double rentalPricePerDay, boolean smokingAllowed) {
    this.name = name;
    this.nbOfSeats = nbOfSeats;
    this.trunkSpace = trunkSpace;
    this.rentalPricePerDay = rentalPricePerDay;
    this.smokingAllowed = smokingAllowed;
    }


    When running the application, it throws the following exception:




    NucleusFatalUserException: Attempt to assign child with key
    "CarType(6614661952700416)" to parent with key
    "CarRentalCompany("Hertz")". Parent keys are immutable




    What do I need to do to get the key of the CarType right?










    share|improve this question



























      0












      0








      0








      I have two classes, CarRentalCompany



      @Entity
      public class CarRentalCompany {

      private static Logger logger = Logger.getLogger(CarRentalCompany.class.getName());

      @Id
      private String name;

      @OneToMany(cascade = CascadeType.ALL)
      private List<Car> cars;

      @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
      private List<CarType> carTypes = new ArrayList<>(); //TODO: kan betere datastructuur zijn

      /***************
      * CONSTRUCTOR *
      ***************/

      public CarRentalCompany()
      {
      // DEFAULT CONSTRUCTOR
      }

      public CarRentalCompany(String name, List<Car> cars) {
      logger.log(Level.INFO, "<{0}> Car Rental Company {0} starting up...", name);
      setName(name);
      this.cars = cars;
      for(Car car:cars)
      carTypes.add(car.getType());
      }
      ...
      }


      and CarType



      @Entity
      public class CarType {

      @Id
      @GeneratedValue(strategy = GenerationType.IDENTITY)
      private Key key;

      private String name;
      private int nbOfSeats;
      private boolean smokingAllowed;
      private double rentalPricePerDay;
      //trunk space in liters
      private float trunkSpace;

      /***************
      * CONSTRUCTOR *
      ***************/

      public CarType()
      {

      }

      public CarType(String name, int nbOfSeats, float trunkSpace, double rentalPricePerDay, boolean smokingAllowed) {
      this.name = name;
      this.nbOfSeats = nbOfSeats;
      this.trunkSpace = trunkSpace;
      this.rentalPricePerDay = rentalPricePerDay;
      this.smokingAllowed = smokingAllowed;
      }


      When running the application, it throws the following exception:




      NucleusFatalUserException: Attempt to assign child with key
      "CarType(6614661952700416)" to parent with key
      "CarRentalCompany("Hertz")". Parent keys are immutable




      What do I need to do to get the key of the CarType right?










      share|improve this question
















      I have two classes, CarRentalCompany



      @Entity
      public class CarRentalCompany {

      private static Logger logger = Logger.getLogger(CarRentalCompany.class.getName());

      @Id
      private String name;

      @OneToMany(cascade = CascadeType.ALL)
      private List<Car> cars;

      @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
      private List<CarType> carTypes = new ArrayList<>(); //TODO: kan betere datastructuur zijn

      /***************
      * CONSTRUCTOR *
      ***************/

      public CarRentalCompany()
      {
      // DEFAULT CONSTRUCTOR
      }

      public CarRentalCompany(String name, List<Car> cars) {
      logger.log(Level.INFO, "<{0}> Car Rental Company {0} starting up...", name);
      setName(name);
      this.cars = cars;
      for(Car car:cars)
      carTypes.add(car.getType());
      }
      ...
      }


      and CarType



      @Entity
      public class CarType {

      @Id
      @GeneratedValue(strategy = GenerationType.IDENTITY)
      private Key key;

      private String name;
      private int nbOfSeats;
      private boolean smokingAllowed;
      private double rentalPricePerDay;
      //trunk space in liters
      private float trunkSpace;

      /***************
      * CONSTRUCTOR *
      ***************/

      public CarType()
      {

      }

      public CarType(String name, int nbOfSeats, float trunkSpace, double rentalPricePerDay, boolean smokingAllowed) {
      this.name = name;
      this.nbOfSeats = nbOfSeats;
      this.trunkSpace = trunkSpace;
      this.rentalPricePerDay = rentalPricePerDay;
      this.smokingAllowed = smokingAllowed;
      }


      When running the application, it throws the following exception:




      NucleusFatalUserException: Attempt to assign child with key
      "CarType(6614661952700416)" to parent with key
      "CarRentalCompany("Hertz")". Parent keys are immutable




      What do I need to do to get the key of the CarType right?







      java google-app-engine jpa






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 24 '18 at 8:34









      Billy Frost

      1,799198




      1,799198










      asked Nov 23 '18 at 12:28









      Wouter VandenputteWouter Vandenputte

      3942414




      3942414
























          1 Answer
          1






          active

          oldest

          votes


















          0














          You are not persisting your CarRentalCompany entity before adding CarType entity. See a
          similar thread here. The persist operation must be used only for new entities. An entity is new when it has never been associated with a database row, meaning that there is no table record in the database to match the entity in question.






          share|improve this answer























            Your Answer






            StackExchange.ifUsing("editor", function () {
            StackExchange.using("externalEditor", function () {
            StackExchange.using("snippets", function () {
            StackExchange.snippets.init();
            });
            });
            }, "code-snippets");

            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "1"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














            draft saved

            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53446752%2fgoogle-appengine-key-exception%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            0














            You are not persisting your CarRentalCompany entity before adding CarType entity. See a
            similar thread here. The persist operation must be used only for new entities. An entity is new when it has never been associated with a database row, meaning that there is no table record in the database to match the entity in question.






            share|improve this answer




























              0














              You are not persisting your CarRentalCompany entity before adding CarType entity. See a
              similar thread here. The persist operation must be used only for new entities. An entity is new when it has never been associated with a database row, meaning that there is no table record in the database to match the entity in question.






              share|improve this answer


























                0












                0








                0







                You are not persisting your CarRentalCompany entity before adding CarType entity. See a
                similar thread here. The persist operation must be used only for new entities. An entity is new when it has never been associated with a database row, meaning that there is no table record in the database to match the entity in question.






                share|improve this answer













                You are not persisting your CarRentalCompany entity before adding CarType entity. See a
                similar thread here. The persist operation must be used only for new entities. An entity is new when it has never been associated with a database row, meaning that there is no table record in the database to match the entity in question.







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Nov 23 '18 at 22:53









                OmairOmair

                1764




                1764
































                    draft saved

                    draft discarded




















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53446752%2fgoogle-appengine-key-exception%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    Wiesbaden

                    Marschland

                    Dieringhausen