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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T18:22:20+00:00 2026-06-05T18:22:20+00:00

I have two tables associated by FK. Table student is mapped like this: @Entity

  • 0

I have two tables associated by FK.

Table student is mapped like this:

@Entity
@Table(name="student")
public class Student implements Serializable {
  ...
  @Id
  @GeneratedValue
  private int id; 

  @ManyToOne(fetch = FetchType.LAZY, optional = true) 
  @JoinColumn(name = "school_ID", nullable = true, insertable = false, updatable = false)
  private School school;

  private Integer school_ID; 

  @Transient
  private boolean editable = false;
}

Table school:

@Entity
@Table(name="school")
public class School implements Serializable {
  ...
  @OneToMany(fetch = FetchType.LAZY, mappedBy = "school")
  private Set<Student> student = new HashSet<Student>(0);

When I try to insert/update student, which isn’t at any school (student.school_ID is null) it reports:

Exception: java.lang.Exception: org.hibernate.exception.ConstraintViolationException:
could not update: [tables.Student#556758]
...
Caused by: com.microsoft.sqlserver.jdbc.SQLServerException: The UPDATE statement
conflicted with the FOREIGN KEY constraint "FK__student__school_ID__57378E7F". The 
conflict occurred in database "DB", table "dbo.school", column 'id'.

Do I have a possibility to insert also null values on FK?

Shall I define it on:

  • entity level or
  • database level?

UPDATE:

I’ve change the private School school = new School(), but when I try to insert/update row, it still reports:

SEVERE: Servlet.service() for servlet [Faces Servlet] in context with path [/DB] threw exception [javax.el.PropertyNotFoundException: /view.xhtml @183,102 value="#{item.school.id}": Target Unreachable, 'school' returned null] with root cause
javax.el.PropertyNotFoundException: /view.xhtml @183,102 value="#{item.school.id}": Target Unreachable, 'school' returned null

view.xhtml:

<rich:column>
  <h:outputText value="#{item.school != null ? item.school.name : null}" rendered="#{!item.editable}"/>
  <h:selectOneMenu id="som" tabindex="1" value="#{item.school.id}"  rendered="#{item.editable}">
    <f:selectItems value="#{myDials.schoolList}"/> 
  </h:selectOneMenu>
</rich:column>
<rich:column>
  • 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-05T18:22:21+00:00Added an answer on June 5, 2026 at 6:22 pm

    You mapped two different fields on the same school_id column:

    private School school;
    private Integer school_ID; 
    

    Remove the school_ID field. You don’t need it, since you already have an association to the School entity.

    And also remove insertable = false, updatable = false from the association mapping. You should use the school field to create, update or remove the association.

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

Sidebar

Related Questions

I have two tables one with ID and NAME table 1 ID | NAME
I have two tables user table user_id | name | 1 | peter |
I have a MySQL database with two tables (simplified for this question): movies table
I use Hibernate with Java. I have two tables which are associated with foreign
I have two tables: table a ida valuea 1 a 2 b 3 c
I have two tables, a user table and a application table: User id username
I have two tables: users and user_depts. Let's say (for this question) that users
I have got two tables in SQL Server 2005: USER Table: information about user
Let's say you have the following two tables: X Table X_ID Y_ID_F X_Value 1
I have SQL Server 2008 database with two tables. The first table is called

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.