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 6648241
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T00:37:57+00:00 2026-05-26T00:37:57+00:00

I m working with Hibernate + Spring and JSF I have a problem when

  • 0

I m working with Hibernate + Spring and JSF

I have a problem when I use a relationship like @OneTomany in Hibernate. For example:

@Entity
@Table(name = "book")
public class Book {

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private long id;
    private String description;
    private String image;
    private int numberOfPages;
    private Date releaseDate;
    private String title;

    @ManyToOne(cascade = CascadeType.ALL)
    @JoinColumn(name = "category_id")
    private Category category;

When I remove CascadeType.ALL and save a book containing a category, the Id of Category becomes null.

Can anyone help me to resolve this problem?

Edit: This is my unit test that causes the error when I remve CascadeType.ALL

BookDao bookDao = (BookDao) applicationContext.getBean("bookDao");
Category category = new Category();
category.setTitle("Title");
Book book = new Book();
book.setCategory(category);
bookDao.save(book);
long id = book.getCategory().getId();
assertTrue(id > 0);
  • 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-26T00:37:58+00:00Added an answer on May 26, 2026 at 12:37 am

    Have a look at “Cascading life cycle” to understand how cascading works. Unless you’re assigning ids manually, an entity only gets an id assigned when it’s saved. If you’re cascading saves from Book to Category, then saving the Book also saves the Category. Without cascading, the Category doesn’t get saved, and therefore it has no id.

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

Sidebar

Related Questions

I have a database table using an enum. This is already working with hibernate
I have working Hibernate/Spring web-app ( HibernateDaoSupport , getHibernateTemplate() , etc). For several tasks
I am working with Spring and Hibernate. I have an object which was retrieved
For my current project I'm working with JSF, Seam and Hibernate and I have
I'm using hibernate JPA (without Spring) and it's working well, but I have come
we're working on a web app with Spring, Hibernate/JPA and Maven. We have several
I'm working on a Java web application (Adobe Flex front-end, JPA/Hibernate/BlazeDS/Spring MVC backend) and
A project I am working on uses Spring 2.5 & JPA with Hibernate as
I've try to implement integration tests for a working application (spring, hibernate, soap, cxf).
I am working in a struts-hibernate application. I have seen a error on 3rd

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.