0

I have two entities, the first of which is:

@Entity
@Table(name="E_CMS_CFG")
public class E_CMS_CFG extends BaseEntity{

    @Id
    @OneToOne(cascade=CascadeType.ALL)//, fetch = FetchType.EAGER)
    @JoinColumns({
        @JoinColumn(name = "CFG_TYPE", nullable = false, referencedColumnName = "CFG_TYPE", columnDefinition = "VARCHAR(32)"),
        @JoinColumn(name = "CFG_TYPE_ID", nullable = false, referencedColumnName = "ID")
        })
    private E_CMS_CFG_TYPE cfgType;

The second entity is:

@Entity
@Table(name="E_CMS_CFG_TYPE")
public class E_CMS_CFG_TYPE extends BaseEntity{

    @Id
    @Column(name = "CFG_TYPE", length = 32)
    private String cfgType;

In the first entity, I use columnDefinition = "VARCHAR(32)" on the CFG_TYPE column; however, in the database, it is creating a cfg_type integer column. Is it possible to create a VARCHAR cfg_type column and not an integer? And if it is, how? I am using Sqlite 3.8.10.1 version.

UPDATE: The link did not help, but if I replace in E_CMS_CFG the @Id with @NaturalId (mutable = false), it works, but it creates it without a primary key.

Michael Gaskill
  • 7,913
  • 10
  • 38
  • 43
FAndrew
  • 248
  • 4
  • 22

1 Answers1

2

You could try to use the natural id annotation here. For example:

@NaturalId (mutable = false)
@Column(name = "CFG_TYPE", unique = true, nullable = false, length = 32)
private String cfgType;

But I think you would still have to provide an id property and that would still be an integer value/column in your database.

I think this Question is a duplicate of "how to use id with string type in jpa hibernate"

I hope that helps!

  • 1
    @FAndrew see my edit. I think your question may be a duplicate. Just follow the Link I've provided. – Gregor Valentin Aug 25 '15 at 07:30
  • did not helped me the link, but if I replace in E_CMS_CFG the Id with NaturalId (mutable = false) it works but it creates without pk – FAndrew Aug 25 '15 at 07:42
  • 1
    OK this is how I meant it. Yeah I think you would still have to provide an extra Id property which hibernate can use as pk internally. This will still be an integer value. – Gregor Valentin Aug 25 '15 at 07:56
  • Yeah now I do with NaturalId hoply in future did not give commplications – FAndrew Aug 25 '15 at 08:05