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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T19:30:27+00:00 2026-05-26T19:30:27+00:00

I’m implementing a rest web service in Java as university assignment so I’m quite

  • 0

I’m implementing a rest web service in Java as university assignment so I’m quite new to such things thus probably I’m doing it in the wrong way.

Anyway the problem is that Dozer can’t map a Hibernate PersistentBag to a java.util.List.

I’m mapping two classes: A and B,

List<Department> A.departments

is mapped to

DepartmentsType B.departments

DepartmentsType has just one property which is

List<DepartmentType> departments

So in the end A.departments is mapped to B.departments.departments, infact this is the mapping:

<mapping>
    <class-a>it.unitn.lsde.persistence.A</class-a>
    <class-b>it.unitn.lsde.generated.B</class-b>

    <field>
        <a>name</a>
        <b>name</b>
    </field>
    <field>
        <a>city</a>
        <b>city</b>
    </field>
    <field> 
        <a>departments</a>
        <b>departments.departments</b>
        <a-hint>it.unitn.lsde.persistence.Department</a-hint>
        <b-hint>it.unitn.lsde.generated.DepartmentType</b-hint>
    </field>
    <field>
        <a>code</a>
        <b>code</b>
    </field>
</mapping>

This is how I define A.departments (Hibernate):

@OneToMany(fetch = FetchType.LAZY, mappedBy = "university", cascade = CascadeType.ALL)
protected List<Department> departments = new ArrayList<Department>();

This is how I define B.departments:

DepartmentsType departments;

And eventually this is how DepartmentsType.departmens is defined:

List<DepartmentType> departments;

Whenever a I try to map class A to class B I get a Field Mapping Error from Dozer:

Source parent class: B
Source field name: departments
Source field type: class org.hibernate.collection.PersistentBag
Source field value: [it.unitn.lsde.persistence.Department@12b3c6b]
Dest parent class: A
Dest field name: departments.department
Dest field type: java.util.List

The exceptions stack point this code to be problemitic:

return (B) mapper.map((A)session.get(A.class, id), B.class);

However when I map class B to class A everything works as expected.
I know that, for a number of reasons, Hibernate is turning what I defined as List into its PersistentBag but this should be a List itself.

I’m not able to find out what i’m doing wrong, why Dozer can map A to B but not B to A.

Thanks in advance

  • 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-26T19:30:28+00:00Added an answer on May 26, 2026 at 7:30 pm

    After hours of searching I’ve found out that I was missing the setter of the List on the DepartmentsType‘s (B.departments) class.

    Without that setter Dozer was not able to map the list coming from Hibernate.

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
Seemingly simple, but I cannot find anything relevant on the web. What is the
I want use html5's new tag to play a wav file (currently only supported
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have thousands of HTML files to process using Groovy/Java and I need to
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
I would like to count the length of a string with PHP. The string

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.