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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T21:49:12+00:00 2026-06-11T21:49:12+00:00

What I am trying to do is make my Play! project use an already

  • 0

What I am trying to do is make my Play! project use an already existing database on MySQL. The connection to the database is fine. My problem lies with linking the foreign keys constraints in the MySQL database to my Play! project’s class’s @ManyToOne relationships.

So basically what I currently have is in my database is:

...
create table clubadmin  (
    clubadmin_id  int not null auto_increment,
    club_id int not null,
    user_id int not null,
    primary key (clubadmin_id),
    constraint fk_clubadmin_club_id foreign key (club_id) references club(club_id), 
    constraint fk_clubadmin_user_id foreign key (user_id) references user(user_id)
);

create table special(
    spec_id int not null auto_increment,
    spec_datetime datetime not null,
    spec_content varchar(500) not null,
    clubadmin_id int not null,
    primary key (spec_id),
    constraint fk_special_clubadmin_id foreign key (clubadmin_id) references clubadmin(clubadmin_id)
);
...

With emphasis on the relationship between special and clubadmin.

In my Play! project I have a ClubAdmin and a Special class that have the following:

package models;

...

@Entity
@Table(name="special")
public class Special extends GenericModel
{
        @Id 
        @GeneratedValue(strategy=GenerationType.AUTO)
        @Required
        public Long spec_id;

        ...

        @ManyToOne
        @Required
        public Clubadmin clubadmin;

        public Special(Clubadmin admin,...)
        {
                ...
                this.clubadmin = admin;
                ...
        }
}

and

package models;

...

@Entity
@Table(name="clubadmin")
public class ClubAdmin extends GenericModel
{

        @Id 
        @GeneratedValue(strategy=GenerationType.AUTO)
        @Required
        public Long clubadmin_id;

        ...

        @OneToMany(mappedBy="clubadmin",cascade=CascadeType.ALL)
        public List<Special> specials;

        public ClubAdmin(...)
        {
                ...
                this.specials=new ArrayList<Special>();
                ...
        }
}

From what I can see, it looks like the creation of the @ManyToOne relationship in the Special class is creating a new field inside the Special table with the name of clubadmin_clubadmin_id that represents the foreign key , regardless of the existence the fk_special_clubadmin_id constraint. This should not be happening.

How do I make Play! realise and use the existing constraints in the database so that it does not create its own?

I am using Play! 1.2.4 and MySQL 5.3

Thanks!

  • 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-11T21:49:13+00:00Added an answer on June 11, 2026 at 9:49 pm

    Add a JoinColumn annotation to your ManyToOne field to specify a column name different than the one inferred by jpa

    Something like

    @JoinColumn(name="clubadmin_id", referencedColumnName="clubadmin_id")
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to use JQTouch to make a basic mobile site to play a
I'm new to both Play! & Scala, but I'm trying to make a service
Trying to make the infamous checkall checkbox for dynamically created rows from a MySQL
I am starting out to play around with Ruby and trying to make a
I'm trying to make a (super) simple software instrument for a new project I'm
I'm trying to make a Button that will play a animation-list when pressed. I
We've got a problem when trying to generate and use a really large proxy
I'm trying to make an app that can play different midi files at the
I'm trying to make a small extension to allow me to play/pause a video
I'm trying to build a AlarmClock for Spotify and make Spotify play a song

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.