Hi everyone I am write Rest api project with R2dbc (non-blocking) but problem is table relation
Task model
@Getter
@Setter
@Entity(name = "task")
@Table(name = "task")
public class Task {
@Id
@Column(name = "id",unique = true,nullable = false)
private Integer id;
@Column(name = "comment_count")
private Integer comment_count;
@Column(name = "completed")
private Boolean completed;
@Column(name = "content")
private String content;
@Column(name = "url")
private String url;
@Column(name = "orderdata")
private Integer orderdata;
@Column(name = "priority")
private Integer priority;
@OneToOne
@JoinColumn(name = "due_id")//this is relation table Due but this relation retunr response null
private Due due;
}
Due model
@Getter
@Setter//Lombok library
@Entity
@Table(name = "due")
public class Due {
@Id
@Column(nullable = false, unique = true, updatable = false)
private Integer id;
@Column(name = "date_data")
private Date date_Data;
@Column
private Boolean recurring;
@Column(name = "string_data")
private String string_data;
}
Tasks Repository//this reactive crud repositroy
@Repository
public interface TasksRepository extends ReactiveCrudRepository<Task,Integer> {
}
Task Manager//this is business layer
@Component
@Slf4j
@RequiredArgsConstructor
public class TaskManager {
private final TasksRepository tasksRepository;
public Flux<Task> findAll() {
return tasksRepository.findAll();
}
}
Task Service//this is service layer
@Service
@RequiredArgsConstructor
public class TasksService {
private final TaskManager taskManager;
public Flux<Task> getAll() {
return taskManager.findAll();
}
}
Task Controller
@RestController
@RequestMapping("/api/tasks")
@RequiredArgsConstructor
public class TasksController {
private final TasksService tasksService;
@GetMapping
public Flux<Task> getAllTasks(){
return tasksService.getAll();
}
}
Task Response
My Rest Api Response Task
{
"id": 1,
"comment_count": 10,
"completed": false,
"content": "new content",
"url": "http:8085.com",
"orderdata": 5,
"priority": 5,
"due": {
"id": 3,
"date_Data": null,
"recurring": null,
"string_data": null
}
Problem One to One Relation Reponse null What is the problem ??? Please help me Thanks
Error Trace
2021-03-20 20:49:57.161 ERROR 13652 --- [actor-tcp-nio-1]
r.n.channel.ChannelOperationsHandler : [id: 0x1126662b,
L:/127.0.0.1:55827 - R:localhost/127.0.0.1:5432] Error was received while
reading the incoming data. The connection will be closed.
java.lang.StackOverflowError: null
at io.netty.util.internal.ReferenceCountUpdater
.isLiveNonVolatile(ReferenceCountUpdt
er.java:88) ~[netty-common-4.1.59.Final.jar:4.1.59.Final]
at
io.netty.buffer.AbstractReferenceCountedByteBuf
.isAccessible(AbstractReferenceCountedByteBuf.java:56) ~[netty-buffer-
4.1.59.Final.jar:4.1.59.Final]
at io.netty.buffer.AbstractByteBuf.ensureAccessible(AbstractByteBuf.java:1455) ~[netty-buffer-4.1.59.Final.jar:4.1.59.Final]
at io.netty.buffer.AbstractByteBuf.checkIndex(AbstractByteBuf.java:1385) ~[netty-buffer-4.1.59.Final.jar:4.1.59.Final]
at io.netty.buffer.UnsafeByteBufUtil.getBytes(UnsafeByteBufUtil.java:481) ~[netty-buffer-4.1.59.Final.jar:4.1.59.Final]
at io.netty.buffer.PooledUnsafeDirectByteBuf.getBytes(PooledUnsafeDirectByteBuf.java:130) ~[netty-buffer-4.1.59.Final.jar:4.1.59.Final]
at io.netty.buffer.PooledSlicedByteBuf.getBytes(PooledSlicedByteBuf.java:235) ~[netty-buffer-4.1.59.Final.jar:4.1.59.Final]
at io.netty.buffer.ByteBufUtil.decodeString(ByteBufUtil.java:1147) ~[netty-buffer-4.1.59.Final.jar:4.1.59.Final]
at io.netty.buffer.AbstractByteBuf.toString(AbstractByteBuf.java:1248) ~[netty-buffer-4.1.59.Final.jar:4.1.59.Final]
at io.netty.buffer.AbstractByteBuf.getCharSequence(AbstractByteBuf.java:515) ~[netty-buffer-4.1.59.Final.jar:4.1.59.Final]
at io.netty.buffer.AbstractByteBuf.readCharSequence(AbstractByteBuf.java:520) ~[netty-buffer-4.1.59.Final.jar:4.1.59.Final]
at io.r2dbc.postgresql.util.ByteBufUtils.decode(ByteBufUtils.java:42) ~[r2dbc-postgresql-0.8.6.RELEASE.jar:0.8.6.RELEASE]
at io.r2dbc.postgresql.codec.AbstractNumericCodec.decodeNumber(AbstractNumericCodec.java:122) ~[r2dbc-postgresql-0.8.6.RELEASE.jar:0.8.6.RELEASE]
at io.r2dbc.postgresql.codec.AbstractNumericCodec.decodeNumber(AbstractNumericCodec.java:89) ~[r2dbc-postgresql-0.8.6.RELEASE.jar:0.8.6.RELEASE]
at io.r2dbc.postgresql.codec.IntegerCodec.doDecode(IntegerCodec.java:49) ~[r2dbc-postgresql-0.8.6.RELEASE.jar:0.8.6.RELEASE]
at io.r2dbc.postgresql.codec.IntegerCodec.doDecode(IntegerCodec.java:30) ~[r2dbc-postgresql-0.8.6.RELEASE.jar:0.8.6.RELEASE]
at io.r2dbc.postgresql.codec.AbstractCodec.decode(AbstractCodec.java:82) ~[r2dbc-postgresql-0.8.6.RELEASE.jar:0.8.6.RELEASE]
at io.r2dbc.postgresql.codec.DefaultCodecs.decode(DefaultCodecs.java:149) ~[r2dbc-postgresql-0.8.6.RELEASE.jar:0.8.6.RELEASE]
at io.r2dbc.postgresql.PostgresqlRow.decode(PostgresqlRow.java:90) ~[r2dbc-postgresql-0.8.6.RELEASE.jar:0.8.6.RELEASE]
at io.r2dbc.postgresql.PostgresqlRow.get(PostgresqlRow.java:77) ~[r2dbc-postgresql-0.8.6.RELEASE.jar:0.8.6.RELEASE]
at io.r2dbc.spi.Row.get(Row.java:76) ~[r2dbc-spi-0.8.3.RELEASE.jar:na]
at org.springframework.data.r2dbc.convert.MappingR2dbcConverter.readFrom(MappingR2dbcConverter.java:173) ~[spring-data-r2dbc-1.2.5.jar:1.2.5]
at org.springframework.data.r2dbc.convert.MappingR2dbcConverter.readEntityFrom(MappingR2dbcConverter.java:294) ~[spring-data-r2dbc-1.2.5.jar:1.2.5]
at org.springframework.data.r2dbc.convert.MappingR2dbcConverter.readFrom(MappingR2dbcConverter.java:166) ~[spring-data-r2dbc-1.2.5.jar:1.2.5]
at org.springframework.data.r2dbc.convert.MappingR2dbcConverter.readEntityFrom(MappingR2dbcConverter.java:294) ~[spring-data-r2dbc-1.2.5.jar:1.2.5]
at org.springframework.data.r2dbc.convert.MappingR2dbcConverter.readFrom(MappingR2dbcConverter.java:166) ~[spring-data-r2dbc-1.2.5.jar:1.2.5]
at org.springframework.data.r2dbc.convert.MappingR2dbcConverter.readEntityFrom(MappingR2dbcConverter.java:294) ~[spring-data-r2dbc-1.2.5.jar:1.2.5]
at org.springframework.data.r2dbc.convert.MappingR2dbcConverter.readFrom(MappingR2dbcConverter.java:166) ~[spring-data-r2dbc-1.2.5.jar:1.2.5]
at org.springframework.data.r2dbc.convert.MappingR2dbcConverter.readEntityFrom(MappingR2dbcConverter.java:294) ~[spring-data-r2dbc-1.2.5.jar:1.2.5]
at org.springframework.data.r2dbc.convert.MappingR2dbcConverter.readFrom(MappingR2dbcConverter.java:166) ~[spring-data-r2dbc-1.2.5.jar:1.2.5]
at org.springframework.data.r2dbc.convert.MappingR2dbcConverter.readEntityFrom(MappingR2dbcConverter.java:294) ~[spring-data-r2dbc-1.2.5.jar:1.2.5]
at org.springframework.data.r2dbc.convert.MappingR2dbcConverter.readFrom(MappingR2dbcConverter.java:166) ~[spring-data-r2dbc-1.2.5.jar:1.2.5]
at org.springframework.data.r2dbc.convert.MappingR2dbcConverter.readEntityFrom(MappingR2dbcConverter.java:294) ~[spring-data-r2dbc-1.2.5.jar:1.2.5]
at org.springframework.data.r2dbc.convert.MappingR2dbcConverter.readFrom(MappingR2dbcConverter.java:166) ~[spring-data-r2dbc-1.2.5.jar:1.2.5]
at org.springframework.data.r2dbc.convert.MappingR2dbcConverter.readEntityFrom(MappingR2dbcConverter.java:294) ~[spring-data-r2dbc-1.2.5.jar:1.2.5]
at org.springframework.data.r2dbc.convert.MappingR2dbcConverter.readFrom(MappingR2dbcConverter.java:166) ~[spring-data-r2dbc-1.2.5.jar:1.2.5]
at org.springframework.data.r2dbc.convert.MappingR2dbcConverter.readEntityFrom(MappingR2dbcConverter.java:294) ~[spring-data-r2dbc-1.2.5.jar:1.2.5]
at org.springframework.data.r2dbc.convert.MappingR2dbcConverter.readFrom(MappingR2dbcConverter.java:166) ~[spring-data-r2dbc-1.2.5.jar:1.2.5]
R2DBC does not support relationships, so JoinColumn
annotation won't work. Instead you can create a DueRepository
and fetch this entity manually.