0

I create tour and travel app using xspringboot and Hibernate jpa.in that application i have two entity class one is turist and other is vechileTtype.I want to map vechiletype entity with turist entity. I use xaamp server for my sql database. but when i mapped these two entity and run the application i get this type of error

Repeated column in mapping for entity: com.main.ToursTravels.model.VechileType column: name (should be mapped with insert="false" update="false")

Turist.java

package com.main.ToursTravels.model;

import java.math.BigDecimal;
import java.util.Date;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.OneToOne;
import javax.persistence.Table;



import lombok.Data;

@Entity
@Table(name="turist")
@Data
public class Turist {
    @Id
    @GeneratedValue(strategy=GenerationType.IDENTITY)
    @Column(name="truist_id")
    private Long truistid;
    @Column(name="turistname")
    private String turistname;
    @Column(name="travel_km")
    private int travelkm;
    @Column(name="travel_date")
    private Date traveldate;
    @Column(name="drivername")
    private String drivername;
    @OneToOne(fetch=FetchType.LAZY,cascade=CascadeType.ALL)
    @JoinColumn(name="booking_id")
    private VechileType vechiletype;
    @Column(name="vechileno")
    private String vechileno;
    @Column(name="total_amount")
    private BigDecimal totalamount;
    @Column(name="BOOKING_status")
    private boolean bookingstatus;


}

VechileType.java

package com.main.ToursTravels.model;

import java.math.BigDecimal;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.OneToOne;
import javax.persistence.PrimaryKeyJoinColumn;
import javax.persistence.Table;



import lombok.Data;

@Entity
@Table(name="vechiletype")
@Data
public class VechileType {
    @Id
    @GeneratedValue(strategy=GenerationType.IDENTITY)
    @Column(name="booking_id")
    private Long  bookingid;
    @OneToOne(fetch=FetchType.LAZY,cascade=CascadeType.ALL,mappedBy="vechiletype")
    private Turist turist;
    @Column(name="name")
    private boolean mini;
    @Column(name="name")
    private boolean sedan;
    @Column(name="name")
    private boolean suv;
    @Column(name="name_per_km")
    private int rateperkm;
    private BigDecimal minprice;

}

application.properties

spring.datasource.driver-class-name = com.mysql.cj.jdbc.Driver
spring.datasource.url=jdbc:mysql://localhost:3306/groserystore?useSSL=false & serveTimezone= UTC & useLegacyDateTimeCode=false
spring.datasource.username=root
spring.datasource.password=
#use of jpa
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQL5InnoDBDialect
spring.JPA.hibernate.ddl.auto=update

1 Answer 1

2

You are mapping 3 different properties to the same column name:

    @Column(name="name")
    private boolean mini;
    @Column(name="name")
    private boolean sedan;
    @Column(name="name")
    private boolean suv;

Use different names instead:

    @Column(name="mini")
    private boolean mini;
    @Column(name="sedan")
    private boolean sedan;
    @Column(name="suv")
    private boolean suv;

A better, more extensible alternative could be to use an enum:

public enum VehicleKind {
   MINI, SEDAN, SUV
}

And in VechileType

@Entity
@Table(name="vechiletype")
@Data
public class VechileType {

    @Enumerated(EnumType.STRING)
    private VehicleKind kind;
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.