Note that there are some explanatory texts on larger screens.

plurals
  1. POPersistency unit fails to make the relation many to many
    primarykey
    data
    text
    <p>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.</p> <p>Any push in the right direction is appreciated.</p> <p>Thank you in advance,</p> <p>David</p> <p>Initialization:</p> <pre><code>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); } </code></pre> <p>The game class:</p> <pre><code>@Entity public class Game implements Serializable{ private String gameNaam; private double prijs; @ManyToMany(mappedBy = "games") private Collection&lt;Developer&gt; developers = new ArrayList&lt;Developer&gt;(); @Id @GeneratedValue(strategy = GenerationType.AUTO) private Long id; public Game(){}; . . //methods . . } </code></pre> <p>The Developer class</p> <pre><code>@Entity public class Developer implements Serializable { private String naam; private String info; @ManyToMany private Collection&lt;Game&gt; games = new ArrayList&lt;Game&gt;(); @Id @GeneratedValue(strategy = GenerationType.AUTO) private Long id; public Developer() { } . . //methods . . } </code></pre> <p>The persistency Unit:</p> <pre><code> &lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;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"&gt; &lt;persistence-unit name="GameDatabaseSitePU" transaction-type="RESOURCE_LOCAL"&gt; &lt;provider&gt;oracle.toplink.essentials.PersistenceProvider&lt;/provider&gt; &lt;class&gt;domainmodel.Developer&lt;/class&gt; &lt;class&gt;domainmodel.Game&lt;/class&gt; &lt;exclude-unlisted-classes&gt;false&lt;/exclude-unlisted-classes&gt; &lt;properties&gt; &lt;property name="toplink.jdbc.user" value="app"/&gt; &lt;property name="toplink.jdbc.password" value="app"/&gt; &lt;property name="toplink.jdbc.url" value="jdbc:derby://localhost:1527/GameDatabase;create=true"/&gt; &lt;property name="toplink.jdbc.driver" value="org.apache.derby.jdbc.ClientDriver"/&gt; &lt;property name="toplink.ddl-generation" value="drop-and-create-tables"/&gt; &lt;/properties&gt; &lt;/persistence-unit&gt; &lt;/persistence&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload