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

  • Home
  • SEARCH
  • 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 6697951
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T06:31:15+00:00 2026-05-26T06:31:15+00:00

I am quite a newbie to Spring JPA in cooperation with ObjectDB database, but

  • 0

I am quite a newbie to Spring JPA in cooperation with ObjectDB database, but I have encountered a problem that I cannot work out.

I have an application written with the mentioned technologies and it works OK, it persists new entities etc. (thus I think there is no problem with the configuration beans), except for updating even the simplest OneToMany/ManyToOne relations. Those updates are not persisted to the database and I cannot figure out why. Here’s the snippet of my code:

Entity Team (1:N):

@Entity
public class Team implements Serializable {
  ...
  List<Player> squad;
  ...
  @OneToMany(mappedBy="team", cascade=CascadeType.PERSIST)
  public List<Player> getSquad() {
    return squad;
  }
  ...
}

Entity Player (N:1)

@Entity
public class Player implements Serializable {
  ...
  private Team team;
  ...
  @ManyToOne
  public Team getTeam() {
    return team;
  }
  ...
}

Here is a snippet from controller using both DAO objects and the problem:

public ModelAndView addPlayer(HttpServletRequest request, HttpServletResponse response) throws Exception {
  ...
  Team t = teamDao.getTeamById(1); // retrieves an object with ID=1
  Player p = playerDao.getPlayerById(1); // retrieves a player with ID=1
  t.getSquad().add(p); // adds a player to the squad -> working fine but does not persist
  System.out.println("Size of squad: " + t.getSquad().size()); // the player is there
  ...
  return new ModelAndView("index.jsp", "team", t);
}

When I try to list all players in the team inside the index.jsp page or try to add another player the same way, the squad is always empty – nothing persisted to the database. Neither the team object, nor the player object. What do I do wrong?

Any help would be appreciated. Thanks.

EDIT: here is my persistence.xml:

<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.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_2_0.xsd">

  <persistence-unit name="NewPU" transaction-type="RESOURCE_LOCAL">
    <provider>com.objectdb.jpa.Provider</provider>
    <properties>
        <property name="javax.persistence.jdbc.url" value="C:/file.odb" />
        <property name="javax.persistence.jdbc.user" value="admin"/>
        <property name="javax.persistence.jdbc.password" value="admin"/>
    </properties>
  </persistence-unit>

P.S. The absolute path "C:/file.odb" is only for demonstration purposes.

and here is Spring configuration:

<mvc:annotation-driven />

<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
  <property name="persistenceUnitName" value="NewPU" />
  <property name="loadTimeWeaver">
    <bean class="org.springframework.instrument.classloading.InstrumentationLoadTimeWeaver" />
  </property>
</bean>

<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
  <property name="entityManagerFactory" ref="entityManagerFactory"/>
</bean>

<tx:annotation-driven transaction-manager="transactionManager" />
  • 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-05-26T06:31:15+00:00Added an answer on May 26, 2026 at 6:31 am

    CascadeType.PERSIST cascades the persistens of a new object but you load a player from the database and attach the player to your team. If you want to cascade that you have to add the CascadeType.MERGE

    cascade = {CascadeType.PERSIST, CascadeType.MERGE}
    

    You may have a look at CascadeType.ALL.

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

Sidebar

Related Questions

I think that this is a newbie type question but I have quite understood
I am a newbie with Spring MVC but I'm quite impressed with its capabilities.
quite a newbie here but here's a small test code that explains my issue.
I'm aware it's a quite simple question but I'm a newbie to C#, ASP.NET
Quite embarrassing really, but I tested creating a database from a spreadsheet with a
I'm a regular expression newbie and I can't quite figure out how to write
Willing to admit I'm a complete .NET newbie, but I have extensive experience in
I am a JPA newbie. I have what I believe is a very simple
I am quite newbie to autoit. I have 2 questions. How to use ControlFocus
I'm quite newbie with c++, and I'm having some trouble figuring out what is

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.