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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T17:58:18+00:00 2026-05-23T17:58:18+00:00

I have the following model (playframework): @Entity public class Album extends Model{ public Album(){

  • 0

I have the following model (playframework):

@Entity
public class Album extends Model{

    public Album(){
        this.creationDate = new Date();
    }

    public Album(String name){
        this.creationDate = new Date();
        this.name = name;
    }

    @Required
    @Column(unique = true)
    public String name;
    @Temporal(javax.persistence.TemporalType.DATE)
    public Date creationDate;
    @OneToMany(cascade=CascadeType.ALL, mappedBy="album")
    @OrderColumn(name="position")
    public List<Image> images = new ArrayList<Image>();    
}

and:

@Entity
public class Image extends Model {

    public Image(String description) {
        this.description= description;
    }
    @Required
    public String description;
    @Required
    @ManyToOne
    @JoinColumn(name="album_id", nullable=false)
    public Album album;
    @Column(name="position")
    public int position;

    public void addAlbum(Album album){
        this.album = album;
        album.images.add(this);
    }
}

In my tests I do the following:

@Test
public void indexColumn(){
    Album album = new Album("newalbum");
    Image image1 = new Image("newimage1");
    Image image2 = new Image("newimage2");
    image1.addAlbum(album);
    image2.addAlbum(album);
    album.save();

}

When I look at the DB, I can see that position is 0 for both images. I think I did exactly that what’s in the hibernate doc Hibernate Documentation, but it is not working. So I am wondering if this is not working in combination with play framework.

Any Ideas?

BR, Rene

  • 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-23T17:58:19+00:00Added an answer on May 23, 2026 at 5:58 pm

    I finally found a working solution here:

    @Entity
    public class Album extends Model{
    
        public Album(){
            this.creationDate = new Date();
        }
    
        public Album(String name){
            this.creationDate = new Date();
            this.name = name;
        }
    
        @Required
        @Column(unique = true)
        public String name;
        @Temporal(javax.persistence.TemporalType.DATE)
        public Date creationDate;
        @OneToMany(cascade=CascadeType.ALL, mappedBy="album")
        @OrderColumn(name="position_index")
        public List<Image> images = new ArrayList<Image>();    
    }
    

    and

    @Entity
    public class Image extends Model {
    
        public Image(String description) {
            this.description= description;
        }
        @Required
        public String description;
        @Required
        @ManyToOne
        public Album album;
    
        public void addAlbum(Album album){
            this.album = album;
            album.images.add(this);
        }
    }
    

    With that mapping Hibernate creates a new Table: album_image which contains album_id,images_id and position_index, this time updated corresponding to the values in the list.

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

Sidebar

Related Questions

I have the following model classes: @Entity @Table(name = title) public final class Title
I have following model: public class FormularModel { [Required] public string Position { get;
I have the following model entity: public class ScheduledTask { public virtual int ScheduledTaskId
I have the following model public class UserViewModel { public String CVR_Nummer { get;
I have the following model class (simplified) class A{ private String name; private List<B>
I have the following model : class Model extends BaseModel { public function save($conn
I have following Model t.string name t.date start_at t.date end_at t.datetime created_at t.datetime updated_at
I have the following model (dumbed down for this question): public class Student {
I have the following model: namespace Storage.Models { public class AdminDetail { public string
I have the following Model pattern: public abstract class PARENTCLASS {...} public class CHILD_A_CLASS

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.