1

I have two table. CategoryMaster and PotentialProject

PotentialProject [potentialProjectID, typeOfProject]

CategoryMaster  [CategoryID, CategoryName]

I want to join typeOfProject and categoryID.

@Entity
@Table(name="CategoryMaster")
public class CategoryMaster
{
    @Id
    @Column(name="CategoryID")
    @GeneratedValue(strategy=GenerationType.IDENTITY)
    private Integer CategoryID;
    private String CategoryName;

    @OneToOne
    @JoinColumn(name="typeOfProject")
    private PotentialProject potentialProject;

    //getter 
    //setter
}

@Entity
@Table(name="PotentialProject")
public class PotentialProject
{
    @Id
    @Column(name="PotentialProjectID")
    @GeneratedValue(strategy=GenerationType.IDENTITY)
    private Integer potentialProjectID;
    private int typeOfProject;

    @OneToOne(mappedBy="potentialProject")
    private CategoryMaster categoryMaster;

    //getter 
    //setter
}

The error message in hibernate is invalid column name typeOfProject. Pls give me some advice. Thank you.

Pune
  • 81
  • 1
  • 9
  • Can you post your entities in full? –  Dec 04 '15 at 06:49
  • yes. please see the updated. – Pune Dec 04 '15 at 06:52
  • check your DB. Very likely the column name in DB does not match with what you mapped. And, why would you want to have DB scheme with such kind of inconsistent naming? – Adrian Shum Dec 04 '15 at 06:56
  • the `@JoinColumn` and `mappedBy` are not correct, see linked duplicate. You are also missing some `@Column` for example for `CategoryName` –  Dec 04 '15 at 06:57
  • @RC He doesn't need `@Column` with `@JoinColumn` and `@OneToOne` – v.ladynev Dec 04 '15 at 07:00
  • @RC I am agree about `CategoryName`. And It should be `categoryName`. And need `@Column` for `typeOfProject` too ;) – v.ladynev Dec 04 '15 at 07:10

2 Answers2

1

Looks like this is correct

@OneToOne(mappedBy="potentialProject")
private CategoryMaster categoryMaster;

But this is not correct

@OneToOne
@JoinColumn(name="typeOfProject")
private PotentialProject potentialProject;

name is a name of a foreign key column! So your code should be something like this

@OneToOne
@JoinColumn(name="fk_potential_project")
private PotentialProject potentialProject;
v.ladynev
  • 19,275
  • 8
  • 46
  • 67
0

Thank you bro @RC & @v.ladynev. I got an solution. I change bi-direction mapping to uni-direction mapping. So

@OneToOne
@PrimaryKeyJoinColumn  
private CategoryMaster categoryMaster;

Nothing to do in CategoryMaster.

Thank you bros.

Pune
  • 81
  • 1
  • 9