Byte Array mapping of a column in Entity class throwing Error - spring-boot

In My entity class "asset_docs" i am using photos_byte as column name defined in postgress sql defined as "photos_byte" as bytea . But whenever i am trying to use JPA framework to save someobject it throws the below error :
o.h.e.j.s.SqlExceptionHelper : ERROR: column "photos_byte" of relation "asset_docs" does not exist
#Id
#Basic(optional = false)
#Column(name = "id")
#GeneratedValue(strategy=GenerationType.IDENTITY)
private Long id;
#Column(name = "created_at")
#Temporal(TemporalType.DATE)
private Date createdAt;
#Lob
#Column(name="photos_byte", columnDefinition="bytea")
private byte[] photosByte;
Whats wrong here ?

Related

Posting Integer array in postgress through Postman on spring boot JPA service

I am trying to post the below request through postman in the item table to a spring boot service . I am using JPA , Postgress , Spring boot .
{
"allGroups" : [1,2,3],
"assetName" : "testname"
}
The Entity class is like below for the Asset table
public class Asset implements Serializable {
private static final long serialVersionUID = 1L;
#Id
#Basic(optional = false)
#Column(name = "id")
#GeneratedValue(strategy=GenerationType.IDENTITY)
private Long id;
private String assetName;
#Type(type = "int-array")
#Column(name = "all_groups")
private Integer[] allGroups;
}
And the corresponding DTO is
#JsonInclude(JsonInclude.Include.NON_NULL)
public class AssetDto {
private long serialVersionUID;
#Max(Integer.MAX_VALUE)
#GeneratedValue(strategy = GenerationType.AUTO)
private Integer id;
#Size(max = 255)
#NotBlank(message = "assetName may not be empty")
private String assetName;
private Integer[] allGroups;
}
When i am posting it is saving the "assetName" property but not the "allGroups" array . How to make it work submit array also .

How to manually setID for new row? Disable autoincrement. Spring

I have that entity:
#Id
#GeneratedValue(strategy = GenerationType.AUTO)
#Column(name = "schema_id")
private Integer id;
#Column(name = "schema_name")
private String schemaName;
#Nationalized
#Lob
#Column(name = "schema_ERD")
private String schemaERD;
#ManyToOne
#JoinColumn(name = "user_idFK")
private Users users;
... getters setters
I am adding new rows like that:
Schemas schemas = new Schemas();
schemas.setSchemaERD(...);
schemas.setSchemaName(...);
schemas.setUsers(...;
schemasRepository.save(schemas);
Everything works but my ID is autoincremented. I have reason to disable that.
Is this possible to do something like that? --->
Schemas schemas = new Schemas();
schemas.setId(100);
schemas.setSchemaERD(...);
schemas.setSchemaName(...);
schemas.setUsers(...;
schemasRepository.save(schemas);
I am all time getting erros: about nulls or something else. In some ways i am not getting error but my row will be added with autoincremented id...
Can someone help? :(

I am not getting unique column using hibernate , for postgresql db

#Entity
#Table(uniqueConstraints={#UniqueConstraint(columnNames={"catgoryId","applcationNo"})})
I tried this explicitly #table
and unique , //but not getting result.
public class DmsDocDetailPojo {
#Id
#GeneratedValue(strategy = GenerationType.IDENTITY)
#Column(columnDefinition = "serial")
private Long dmsDocId;
#Column
private String stateCode="AI";
#Column(name = "applicationNo", unique = true,nullable=false)
#NotNull
private String applcationNo;
#Column(name = "catgoryId", unique = true,nullable=false)
private String catgoryId;
#CreationTimestamp
#Column( nullable = false, updatable=false)
private Date doc_uploaded_dt;
#UpdateTimestamp
private Date doc_updated_dt;
#Column(name = "document_file", columnDefinition = "BYTEA")
private byte[] document_file;
#Column
private String fileName;
#Column
private Integer fileSize;
}
check your database primary key it should be an auto increment

join table and get data based on field value JPA

I have two entities
#Entity
public class Module {
#Id
#GeneratedValue(strategy = GenerationType.AUTO)
private Integer id;
private String name;
private String descr;
#OneToMany(cascade = {CascadeType.ALL})
#JoinColumn(name="ID", referencedColumnName="ID")
private List<Permissions> perms;
}
#Entity
public class Permissions {
#Id
#GeneratedValue(strategy = GenerationType.AUTO)
private Integer id;
private Integer clientId;
private String role;
private Character endorseCreate;
private Character endorseUpdate;
private Character endorseDelete;
private Character endorseView;
I am trying to fetch data by first Module.name and Permissions.clientId and Permissions.role
Something like in sql
select * from Module m, Permissions p where m.id=p.id and p.clientId=1 and p.role='ADMIN'
How can I achieve using JPA, I am using spring data aswell.
Can a method be declared in CRUD Repo provided by spring data?
I think the issue is I am unable to find way to pass values to fetch data.
Any help is greatly appreciated

JPQL Insert by selecting query not working

I have two below entity. One is MatchTable another is MatchLog.
#Entity
public class MatchTable {
#Id
#GeneratedValue(strategy = GenerationType.IDENTITY)
#Column(name = "id", updatable = false, nullable = false)
private Long id;
#ManyToOne
private Integer primaryID;
#ManyToOne
private Integer suspectedID;
#Column(nullable=false)
private Integer status;
//getter and setter
}
#Entity
public class MatchLog {
#Id
#GeneratedValue(strategy = GenerationType.IDENTITY)
#Column(name = "id", updatable = false, nullable = false)
private Long id;
#OneToOne
private MatchTable referenceID;
#Column(nullable=false)
private Long primaryID;
#Column(nullable=false)
private Long suspectedID;
#Column(nullable=false)
private Integer status;
//getter and setter
}
If status of MatchTable change,these row will be inserted into MatchLog. I have tried with the below JPQL query.
#Query("INSERT INTO MatchLog (referenceID.id,primaryID,suspectedID,status) SELECT id,primaryID,suspectedID,status from MatchTable where (primaryID = :ID or suspectedID = :ID)")
int updateMatchLogTable(#Param("ID") long ID);
But this JPQL query is not working. Please suggest me what will be the JPQL query to insert change rows from MatchTable to MatchLog.
Unless I'm mistaken, JPA does not support "insert into select". You can change as native query.

Resources