Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7763885
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T14:46:20+00:00 2026-06-01T14:46:20+00:00

Ok this is a weird problem because I had it working before. So I

  • 0

Ok this is a weird problem because I had it working before.
So I have 2 classes: game and developer. They have a many to many relationship.
The persistency unit makes automatically the table game_developer.
Thus there are 3 tables: game developer and game_developer.
When I enter Information inside the database. The table game and developer will get there values as normal but the table game_developer will remain empty. So the relationship isn’t recognized.
Also when I run the webapp everything inside the tables should be dropped. The developer drops fine but the game remains to exist.

Any push in the right direction is appreciated.

Thank you in advance,

David

Initialization:

try {
        gameOrganizer = (GameOrganizer) getServletContext().getAttribute("database");

        Game game = new Game("Counter Strike: source");
        Game game2 = new Game("Battlefield: bad company 3");
        Game game3 = new Game("Killing floor");

        Developer devel = new Developer("valve");
        Developer devel2 = new Developer("EA Games");
        Developer devel2b = new Developer("DICE");
        Developer devel3 = new Developer("Ubisoft");

        //The GameOrganizer is the controller between the model en the view. 
        //The view being the website.
        //So gameOrganizer.addGame(game) will persist the object to the database.

        gameOrganizer.addGame(game);
        gameOrganizer.addGame(game2);
        gameOrganizer.addGame(game3);

        gameOrganizer.addDeveloper(devel);
        gameOrganizer.addDeveloper(devel2);
        gameOrganizer.addDeveloper(devel2b);
        gameOrganizer.addDeveloper(devel3);

        game.addDeveloper(devel);
        devel.getGames().add(game);

        game2.addDeveloper(devel2);
        devel2.getGames().add(game2);

        game2.addDeveloper(devel2b);
        devel2b.getGames().add(game2);

        game3.addDeveloper(devel3);
        devel3.getGames().add(game3);

    } catch (DatabaseException ex) {
        Logger.getLogger(GameController.class.getName()).log(Level.SEVERE, null, ex);
    } catch (DomainException ex) {
        Logger.getLogger(GameController.class.getName()).log(Level.SEVERE, null, ex);
    }

The game class:

@Entity
public class Game implements Serializable{

    private String gameNaam;
    private double prijs;
    @ManyToMany(mappedBy = "games")
    private Collection<Developer> developers = new ArrayList<Developer>();

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id;

    public Game(){};
    .
    .
    //methods
    .
    .
  }

The Developer class

@Entity
public class Developer implements Serializable  {

    private String naam;
    private String info;
    @ManyToMany
    private Collection<Game> games = new ArrayList<Game>();
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id;

    public Developer() {
    }
    .
    .
    //methods
    .
    .
 }

The persistency Unit:

  <?xml version="1.0" encoding="UTF-8"?>
 <persistence version="1.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd">
 <persistence-unit name="GameDatabaseSitePU" transaction-type="RESOURCE_LOCAL">
   <provider>oracle.toplink.essentials.PersistenceProvider</provider>
    <class>domainmodel.Developer</class>
    <class>domainmodel.Game</class>
    <exclude-unlisted-classes>false</exclude-unlisted-classes>
    <properties>
      <property name="toplink.jdbc.user" value="app"/>
      <property name="toplink.jdbc.password" value="app"/>
      <property name="toplink.jdbc.url" value="jdbc:derby://localhost:1527/GameDatabase;create=true"/>
      <property name="toplink.jdbc.driver" value="org.apache.derby.jdbc.ClientDriver"/>
      <property name="toplink.ddl-generation" value="drop-and-create-tables"/>
    </properties>
  </persistence-unit>
</persistence>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T14:46:22+00:00Added an answer on June 1, 2026 at 2:46 pm

    The relationship isn’t recognized because you persist the objects before you establish the relationships. Do the calls gameOrganizer.add..() after you add the objects to each others collections. Also add persist on cascade to your many-to-many relationship of developers:

    @ManyToMany(cascade = CascadeType.PERSIST, mappedBy = "games")
    private Collection<Developer> developers = new ArrayList<Developer>();
    

    Then you only need to persist the games.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this weird problem with setting up cookies with PHP. Everything worked fine
This is a weird problem I have started having recently. My team is developing
This is a weird problem. I have a solution for it, but I don't
This is a really weird problem that I have been having. When I download
This is a (to me) pretty weird problem, because it was already running perfectly
I have a rather weird problem. Because of a certain PECL bug , I
I've got this weird problem - I'm calling ChangeServiceConfig on a newly installed service
I'm experiencing this weird problem which my scrollbar jumps by itself to somewhere that
Today, I ran into this weird problem with a user using Mac OS X.
I'm new to Ruby, so I'm having some trouble understanding this weird exception problem

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.