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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T06:41:33+00:00 2026-05-13T06:41:33+00:00

I have been struggling with not being able to have the EntityManager be instantiated

  • 0

I have been struggling with not being able to have the EntityManager be instantiated when I add a OneToMany column to a class that already has a OneToMany column.

Right now the EducationInfo has a OneToOne to user, since each row will be unique to a person, but I want to be able to load all the education information given a username.

I am not changing the orm.xml file when I add the column, I just drop the database so it can be recreated.

class User {
  @Id
  @GeneratedValue(){val strategy = GenerationType.AUTO}
  var id : Int = _

  @Column{val nullable = false, val length=32}
  var firstName : String = ""
  var lastName : String = ""

  @Column{val nullable = false, val unique = true, val length = 30}
  var username : String = ""

  @OneToMany{val fetch = FetchType.EAGER, val cascade=Array(CascadeType.ALL)}
  var address : java.util.List[Address] = new java.util.ArrayList[Address]()

  @OneToMany{val fetch = FetchType.EAGER, val cascade=Array(CascadeType.ALL), val mappedBy="user"}
  var educationInfo : java.util.List[EducationInfo] = new java.util.ArrayList[EducationInfo]()

If I don’t include the last column then my unit test works fine, but if I include this then all my unit tests fail.

Here is the class it is trying to use, and the unit tests for this class works fine:

@Entity
@Table{val name="educationinfo"}
class EducationInfo {
  @Id
  @GeneratedValue(){val strategy = GenerationType.AUTO}
  var id : Long = _

  @Column{val nullable = false, val length = 100}
  var name : String = "";

  @OneToOne{val fetch = FetchType.EAGER, val cascade = Array(CascadeType.PERSIST, CascadeType.REMOVE)}
  @JoinColumn{val name = "educationinfo_address_fk", val nullable = false}
  var location : Address = _

  @ManyToOne{val fetch = FetchType.LAZY, val cascade=Array(CascadeType.PERSIST)}
  @JoinColumn{val name = "educationinfo_user_fk", val nullable = false}
  var user : User = _

  @Column{val nullable = false, val length = 100}
  var degree : String = ""

  @Temporal(TemporalType.DATE)
  @Column{val nullable = true}
  var startyear : Date = new Date()
  var endyear : Date = new Date()

  @Column{val nullable = true, val length = 1000}
  var description : String = ""
}

I am also curious if there is some way to know what the error is that prevents the EntityManager from being instantiated, but the main problem is what may be causing a problem when I add this column to User?

UPDATE:

Removed a part that was in error.

UPDATE 2:

I changed the user column in the education entity to be @ManyToOne and all my unit tests failed.

The end of my error log is this:

15035 [main] INFO org.hibernate.cfg.SettingsFactory - Default entity-mode: pojo
15035 [main] INFO org.hibernate.cfg.SettingsFactory - Named query checking : enabled
15047 [main] INFO org.hibernate.impl.SessionFactoryImpl - building session factory
[PersistenceUnit: jpaweb] Unable to build EntityManagerFactory
[PersistenceUnit: jpaweb] Unable to build EntityManagerFactory

Then EntityManager is null in every test, so it fails.

UPDATE 3:

The Address entity has no foreign keys to anything, as it is called from several entities.

Could this problem be caused by using Apache Derby as the database?

Unfortunately I don’t get any error message. I run this from within maven, and though I delete the database each time I can’t tell what it happening that is wrong. The @ManyToOne from EducationInfo -> User doesn’t cause any problems, but @OneToMany -> EducationInfo from User does.

UPDATE 4:

I added a mappedBy to the User entity as suggested. I had that in another column definition, as I have five definitions that won’t work, and I believe they are all for the same reason, so I am just testing with one. Unfortunately it still leads to the EntiyManagerFactory not being built so all the tests fail.

FINAL UPDATE:

The actual case was

cannot simultaneously fetch multiple
bags

so I just removed the FetchType completely from EducationInfo and the problem went away.

  • 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-13T06:41:33+00:00Added an answer on May 13, 2026 at 6:41 am

    OneToMany‘s complement mapping on the other side of association is ManyToOne, it cannot be OneToOne. That’s what’s causing EntityManager to fail.

    It works when you remove the last line from User because then you’re only left with OneToMany to Address and, although not shown here, presumably Address doesn’t have a OneToOne link to User.

    I’m no Scala expert; in Java you normally get an error and a stack trace printed when EntityManager fails to initialize; error message is not always extremely descriptive but usually says what mapping it has a problem with. Perhaps you need to tweak your logging settings if you don’t get that error.

    I didn’t quite understand your model:

    Basically, a user should be able to
    have several addresses, so I expect it
    will become a ManyToMany, but each use
    can also have several instances of
    education information, so the need for
    ManyToOne.

    That sounds like @OneToMany from User to Address to me and (if “use” meant “user”) as @OneToMany from User to EducationInfo.

    Right now the EducationInfo has a
    OneToOne to user, since each row will
    be unique to a person, but I want to
    be able to load all the education
    information given a username.

    That conflicts with above. Either you can have several EducationInfo per User or it’s “unique to a person”.

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

Sidebar

Related Questions

I've been struggling with something at work that I'm not really in the mood
I have been struggling with the best way to make sure that the certain
I've been struggling with a really strange behavior that I do not manage to
I have been struggling with this problem, read many questions, articles but could not
I have been struggling with this for a while now. given a set of
I have been struggling with Core Data sigh so I decided to work this
I have been struggling with setting up an iOS (Objective-C) app which utilizes the
I have been struggling with this error for more than two hours: error: aggregate
I have been struggling for a few days trying to find out how come
I have been struggling all afternoon trying to get a simple mailto: tag to

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.