Reputation: 1315
I hope you're doing fine, I am having a little problem That I could not solve alone, I won't lie, I am a begginer when it comes to Spring and Java in general.
I am having this little bug as the title mentioned, I am trying to get data from a table called tr_type_conformite
, so I created a Java DAO class to get the data from that table:
@Repository
public class ConformiteDaoImpl extends AbstractDaoImpl<Object, Long> implements ConformiteDao {
@Autowired
private ConfirmiteContratDaoJPA conformiteDaoJPA;
@SuppressWarnings({ "unchecked", "rawtypes" })
@Override
public CrudRepository getCrudRepositoryImpl() {
// TODO Auto-generated method stub
return null;
}
@Override
public List<TrTypeConformite> recupererListeConformitePourContrat() {
// TODO Auto-generated method stub
return getJPAQueryFactory().selectFrom(QTrTypeConformite.trTypeConformite).fetch();
}
}
And here is my Entity :
@Entity
@Table(name = "tr_type_conformite")
@Getter @Setter
public class TrTypeConformite extends AbstractTrEntity {
private static final long serialVersionUID = 1L;
@Column(name = "code", nullable = false, length=11)
private String code;
@Column(name = "type", nullable = false)
private EnumTypeConformite type;
@Column(name = "ordre", nullable = false, length=11)
private int ordre;
}
And Here is my Enum :
public enum EnumTypeConformite {
VIGIL("VIGIL"),
PPE("PPE"),
T("T");
private String value;
private EnumTypeConformite(String value) {
this.value = value;
}
public String getValue(){
return value;
}
}
But when I execute a service that call my DAO method, I get this big error :
Caused by: java.sql.SQLException: Invalid value for getInt() - 'T'
And of cource a big list of where my error came from, it is when I excute my service that call my DAO class.
Any Help would be much appreciated.
Upvotes: 3
Views: 861
Reputation: 1561
The default JPA mapping of enum
field is int
column (see EnumType.ORDINAL). If your column is string you need to use EnumType.STRING.
Try to annotate enum
field like this:
@Enumerated(EnumType.STRING)
@Column(name = "type", nullable = false)
private EnumTypeConformite type;
Upvotes: 4