Insert data in several table using single JPA query












-1















I want to create JPA queries for risk filters using several tables. I have these tables which I would like to use for storing data:



Risk filter:



@Entity
@Table(name = "risk_filters")
public class RiskFilters implements Serializable {

private static final long serialVersionUID = -31232741713890134L;

@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "id", unique = true, updatable = false, nullable = false)
private int id;

@Column(length = 4)
private Integer terminal_id;

@Column(length = 255)
private String filter_class;

@Column(name = "FILTER_SETTINGS", columnDefinition = "TEXT", length = 65535)
private String filter_settings;

@Column(length = 4)
private Integer position;

@Column(length = 4)
private Integer parent_id;

@Column
private LocalDateTime created_at;

@Column
private TemporalType updated_at;
.....
}


Risk params:



@Entity
@Table(name = "risk_parameters")
public class RiskParameters implements Serializable {

private static final long serialVersionUID = 6828168899788931021L;

@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "id", unique = true, updatable = false, nullable = false)
private int id;

@Column(length = 4)
private Integer payment_transaction_id;

@Column(length = 32)
private String name;

@Column(length = 128)
private String value;

@Column
private LocalDateTime created_at;

@Column
private LocalDateTime updated_at;
....
}


Risk Details:



@Entity
@Table(name = "risk_details")
public class RiskDetails implements Serializable {

private static final long serialVersionUID = 6122869200132217334L;

@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "id", unique = true, updatable = false, nullable = false)
private int id;

@Column(length = 4)
private Integer payment_transaction_id;

@Column(length = 32)
private String service_name;

@Column(length = 64)
private String name;

@Column(length = 512)
private String value;
.....
}


How I can insert data into these entities with single insert and get data with single select?



I would like to use JPA in order to get and insert data.










share|improve this question


















  • 1





    can you explain about the dependency among all tables?

    – GauravRai1512
    Nov 16 '18 at 10:49













  • An INSERT in SQL inserts into a single table, not multiple. And? Post what you have tried and what is the "problem" ? (apart from the fact that you have no relationships so are using JPA for something that it is not suited for)

    – user3973283
    Nov 16 '18 at 11:01













  • @GauravRai1512 I have one main table RiskFilters and additional RiskParameters and RiskDetails. In order to store many configuration values I need to use SQL one SQL queries in order to use them. Can you propose Insert and select for them?

    – Peter Penzov
    Nov 16 '18 at 11:04











  • You are using an Object Relational Mapper the purpose of which is prevent the need for manually creating SQL statements. You should then redefine your question, clearly explaining the relationship between the entities.

    – Alan Hay
    Nov 16 '18 at 12:02
















-1















I want to create JPA queries for risk filters using several tables. I have these tables which I would like to use for storing data:



Risk filter:



@Entity
@Table(name = "risk_filters")
public class RiskFilters implements Serializable {

private static final long serialVersionUID = -31232741713890134L;

@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "id", unique = true, updatable = false, nullable = false)
private int id;

@Column(length = 4)
private Integer terminal_id;

@Column(length = 255)
private String filter_class;

@Column(name = "FILTER_SETTINGS", columnDefinition = "TEXT", length = 65535)
private String filter_settings;

@Column(length = 4)
private Integer position;

@Column(length = 4)
private Integer parent_id;

@Column
private LocalDateTime created_at;

@Column
private TemporalType updated_at;
.....
}


Risk params:



@Entity
@Table(name = "risk_parameters")
public class RiskParameters implements Serializable {

private static final long serialVersionUID = 6828168899788931021L;

@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "id", unique = true, updatable = false, nullable = false)
private int id;

@Column(length = 4)
private Integer payment_transaction_id;

@Column(length = 32)
private String name;

@Column(length = 128)
private String value;

@Column
private LocalDateTime created_at;

@Column
private LocalDateTime updated_at;
....
}


Risk Details:



@Entity
@Table(name = "risk_details")
public class RiskDetails implements Serializable {

private static final long serialVersionUID = 6122869200132217334L;

@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "id", unique = true, updatable = false, nullable = false)
private int id;

@Column(length = 4)
private Integer payment_transaction_id;

@Column(length = 32)
private String service_name;

@Column(length = 64)
private String name;

@Column(length = 512)
private String value;
.....
}


How I can insert data into these entities with single insert and get data with single select?



I would like to use JPA in order to get and insert data.










share|improve this question


















  • 1





    can you explain about the dependency among all tables?

    – GauravRai1512
    Nov 16 '18 at 10:49













  • An INSERT in SQL inserts into a single table, not multiple. And? Post what you have tried and what is the "problem" ? (apart from the fact that you have no relationships so are using JPA for something that it is not suited for)

    – user3973283
    Nov 16 '18 at 11:01













  • @GauravRai1512 I have one main table RiskFilters and additional RiskParameters and RiskDetails. In order to store many configuration values I need to use SQL one SQL queries in order to use them. Can you propose Insert and select for them?

    – Peter Penzov
    Nov 16 '18 at 11:04











  • You are using an Object Relational Mapper the purpose of which is prevent the need for manually creating SQL statements. You should then redefine your question, clearly explaining the relationship between the entities.

    – Alan Hay
    Nov 16 '18 at 12:02














-1












-1








-1








I want to create JPA queries for risk filters using several tables. I have these tables which I would like to use for storing data:



Risk filter:



@Entity
@Table(name = "risk_filters")
public class RiskFilters implements Serializable {

private static final long serialVersionUID = -31232741713890134L;

@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "id", unique = true, updatable = false, nullable = false)
private int id;

@Column(length = 4)
private Integer terminal_id;

@Column(length = 255)
private String filter_class;

@Column(name = "FILTER_SETTINGS", columnDefinition = "TEXT", length = 65535)
private String filter_settings;

@Column(length = 4)
private Integer position;

@Column(length = 4)
private Integer parent_id;

@Column
private LocalDateTime created_at;

@Column
private TemporalType updated_at;
.....
}


Risk params:



@Entity
@Table(name = "risk_parameters")
public class RiskParameters implements Serializable {

private static final long serialVersionUID = 6828168899788931021L;

@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "id", unique = true, updatable = false, nullable = false)
private int id;

@Column(length = 4)
private Integer payment_transaction_id;

@Column(length = 32)
private String name;

@Column(length = 128)
private String value;

@Column
private LocalDateTime created_at;

@Column
private LocalDateTime updated_at;
....
}


Risk Details:



@Entity
@Table(name = "risk_details")
public class RiskDetails implements Serializable {

private static final long serialVersionUID = 6122869200132217334L;

@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "id", unique = true, updatable = false, nullable = false)
private int id;

@Column(length = 4)
private Integer payment_transaction_id;

@Column(length = 32)
private String service_name;

@Column(length = 64)
private String name;

@Column(length = 512)
private String value;
.....
}


How I can insert data into these entities with single insert and get data with single select?



I would like to use JPA in order to get and insert data.










share|improve this question














I want to create JPA queries for risk filters using several tables. I have these tables which I would like to use for storing data:



Risk filter:



@Entity
@Table(name = "risk_filters")
public class RiskFilters implements Serializable {

private static final long serialVersionUID = -31232741713890134L;

@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "id", unique = true, updatable = false, nullable = false)
private int id;

@Column(length = 4)
private Integer terminal_id;

@Column(length = 255)
private String filter_class;

@Column(name = "FILTER_SETTINGS", columnDefinition = "TEXT", length = 65535)
private String filter_settings;

@Column(length = 4)
private Integer position;

@Column(length = 4)
private Integer parent_id;

@Column
private LocalDateTime created_at;

@Column
private TemporalType updated_at;
.....
}


Risk params:



@Entity
@Table(name = "risk_parameters")
public class RiskParameters implements Serializable {

private static final long serialVersionUID = 6828168899788931021L;

@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "id", unique = true, updatable = false, nullable = false)
private int id;

@Column(length = 4)
private Integer payment_transaction_id;

@Column(length = 32)
private String name;

@Column(length = 128)
private String value;

@Column
private LocalDateTime created_at;

@Column
private LocalDateTime updated_at;
....
}


Risk Details:



@Entity
@Table(name = "risk_details")
public class RiskDetails implements Serializable {

private static final long serialVersionUID = 6122869200132217334L;

@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "id", unique = true, updatable = false, nullable = false)
private int id;

@Column(length = 4)
private Integer payment_transaction_id;

@Column(length = 32)
private String service_name;

@Column(length = 64)
private String name;

@Column(length = 512)
private String value;
.....
}


How I can insert data into these entities with single insert and get data with single select?



I would like to use JPA in order to get and insert data.







java jpa spring-data-jpa spring-data jpa-2.0






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 16 '18 at 10:44









Peter PenzovPeter Penzov

20661191398




20661191398








  • 1





    can you explain about the dependency among all tables?

    – GauravRai1512
    Nov 16 '18 at 10:49













  • An INSERT in SQL inserts into a single table, not multiple. And? Post what you have tried and what is the "problem" ? (apart from the fact that you have no relationships so are using JPA for something that it is not suited for)

    – user3973283
    Nov 16 '18 at 11:01













  • @GauravRai1512 I have one main table RiskFilters and additional RiskParameters and RiskDetails. In order to store many configuration values I need to use SQL one SQL queries in order to use them. Can you propose Insert and select for them?

    – Peter Penzov
    Nov 16 '18 at 11:04











  • You are using an Object Relational Mapper the purpose of which is prevent the need for manually creating SQL statements. You should then redefine your question, clearly explaining the relationship between the entities.

    – Alan Hay
    Nov 16 '18 at 12:02














  • 1





    can you explain about the dependency among all tables?

    – GauravRai1512
    Nov 16 '18 at 10:49













  • An INSERT in SQL inserts into a single table, not multiple. And? Post what you have tried and what is the "problem" ? (apart from the fact that you have no relationships so are using JPA for something that it is not suited for)

    – user3973283
    Nov 16 '18 at 11:01













  • @GauravRai1512 I have one main table RiskFilters and additional RiskParameters and RiskDetails. In order to store many configuration values I need to use SQL one SQL queries in order to use them. Can you propose Insert and select for them?

    – Peter Penzov
    Nov 16 '18 at 11:04











  • You are using an Object Relational Mapper the purpose of which is prevent the need for manually creating SQL statements. You should then redefine your question, clearly explaining the relationship between the entities.

    – Alan Hay
    Nov 16 '18 at 12:02








1




1





can you explain about the dependency among all tables?

– GauravRai1512
Nov 16 '18 at 10:49







can you explain about the dependency among all tables?

– GauravRai1512
Nov 16 '18 at 10:49















An INSERT in SQL inserts into a single table, not multiple. And? Post what you have tried and what is the "problem" ? (apart from the fact that you have no relationships so are using JPA for something that it is not suited for)

– user3973283
Nov 16 '18 at 11:01







An INSERT in SQL inserts into a single table, not multiple. And? Post what you have tried and what is the "problem" ? (apart from the fact that you have no relationships so are using JPA for something that it is not suited for)

– user3973283
Nov 16 '18 at 11:01















@GauravRai1512 I have one main table RiskFilters and additional RiskParameters and RiskDetails. In order to store many configuration values I need to use SQL one SQL queries in order to use them. Can you propose Insert and select for them?

– Peter Penzov
Nov 16 '18 at 11:04





@GauravRai1512 I have one main table RiskFilters and additional RiskParameters and RiskDetails. In order to store many configuration values I need to use SQL one SQL queries in order to use them. Can you propose Insert and select for them?

– Peter Penzov
Nov 16 '18 at 11:04













You are using an Object Relational Mapper the purpose of which is prevent the need for manually creating SQL statements. You should then redefine your question, clearly explaining the relationship between the entities.

– Alan Hay
Nov 16 '18 at 12:02





You are using an Object Relational Mapper the purpose of which is prevent the need for manually creating SQL statements. You should then redefine your question, clearly explaining the relationship between the entities.

– Alan Hay
Nov 16 '18 at 12:02












1 Answer
1






active

oldest

votes


















0














Its possible if you have relation between tables(risk_filters,risk_parameters & risk_details) i.e. primary key and foreign key relationship.



Suppose risk_filters has one to one relationship with risk_parameters & risk_details, then the Entity will be look like



@Entity
@Table(name = "risk_filters")
public class RiskFilters implements Serializable {

private static final long serialVersionUID = -31232741713890134L;

@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "id", unique = true, updatable = false, nullable = false)
private int id;

@Column(length = 4)
private Integer terminal_id;

@Column(length = 255)
private String filter_class;

@Column(name = "FILTER_SETTINGS", columnDefinition = "TEXT", length = 65535)
private String filter_settings;

@Column(length = 4)
private Integer position;

@Column(length = 4)
private Integer parent_id;

@Column
private LocalDateTime created_at;

@Column
private TemporalType updated_at;

@OneToOne
@JoinColumn(name="risk_filter_id", nullable=false)
private RiskParameters riskParameters;

@OneToOne
@JoinColumn(name="risk_filter_id", nullable=false)
private RiskDetails riskDetails;
.....
}


and the call save method to save only RiskFilters Entity as below.



riskFilterObject.setRiskDetails(riskDetailsObject);
riskFilterObject.setRiskParamarets(riskParametersObject);
repository.save(riskFilterObject);// update 3 tables
repository.save(riskDetailsObject); // update only risk_details table
repository.save(riskParametersObject);// update only risk_parameters table


Update:




How about select? Can you show me how to implement select from all
entities?




RiskFilters filters = riskFiltersRepository.findOne(id);
// for Complete netsed RiskFilters Entity object

RiskParameter param = riskParameterRepository.findOne(id);
// for only RiskParameter Entity object

RiskDetails details = riskDetailsRepository.findOne(id);
// for only RiskDetails Entity object






share|improve this answer


























  • Yes but I have filter with 2 and filter with 8 settings. I have to use different tables for different cases.

    – Peter Penzov
    Nov 16 '18 at 12:09













  • if you want to save R.Param & R.Details individually u can do that, it wont affect Risk_filter as we haven't mapped bidirectionally.

    – TheSprinter
    Nov 16 '18 at 12:13











  • Ok, can you show me JPA example using my entities in my original post?

    – Peter Penzov
    Nov 16 '18 at 12:23











  • updated code at the end, check last 3 lines

    – TheSprinter
    Nov 16 '18 at 12:27











  • How about select? Can you show me how to implement select from all entities?

    – Peter Penzov
    Nov 16 '18 at 12:42












Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53336246%2finsert-data-in-several-table-using-single-jpa-query%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














Its possible if you have relation between tables(risk_filters,risk_parameters & risk_details) i.e. primary key and foreign key relationship.



Suppose risk_filters has one to one relationship with risk_parameters & risk_details, then the Entity will be look like



@Entity
@Table(name = "risk_filters")
public class RiskFilters implements Serializable {

private static final long serialVersionUID = -31232741713890134L;

@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "id", unique = true, updatable = false, nullable = false)
private int id;

@Column(length = 4)
private Integer terminal_id;

@Column(length = 255)
private String filter_class;

@Column(name = "FILTER_SETTINGS", columnDefinition = "TEXT", length = 65535)
private String filter_settings;

@Column(length = 4)
private Integer position;

@Column(length = 4)
private Integer parent_id;

@Column
private LocalDateTime created_at;

@Column
private TemporalType updated_at;

@OneToOne
@JoinColumn(name="risk_filter_id", nullable=false)
private RiskParameters riskParameters;

@OneToOne
@JoinColumn(name="risk_filter_id", nullable=false)
private RiskDetails riskDetails;
.....
}


and the call save method to save only RiskFilters Entity as below.



riskFilterObject.setRiskDetails(riskDetailsObject);
riskFilterObject.setRiskParamarets(riskParametersObject);
repository.save(riskFilterObject);// update 3 tables
repository.save(riskDetailsObject); // update only risk_details table
repository.save(riskParametersObject);// update only risk_parameters table


Update:




How about select? Can you show me how to implement select from all
entities?




RiskFilters filters = riskFiltersRepository.findOne(id);
// for Complete netsed RiskFilters Entity object

RiskParameter param = riskParameterRepository.findOne(id);
// for only RiskParameter Entity object

RiskDetails details = riskDetailsRepository.findOne(id);
// for only RiskDetails Entity object






share|improve this answer


























  • Yes but I have filter with 2 and filter with 8 settings. I have to use different tables for different cases.

    – Peter Penzov
    Nov 16 '18 at 12:09













  • if you want to save R.Param & R.Details individually u can do that, it wont affect Risk_filter as we haven't mapped bidirectionally.

    – TheSprinter
    Nov 16 '18 at 12:13











  • Ok, can you show me JPA example using my entities in my original post?

    – Peter Penzov
    Nov 16 '18 at 12:23











  • updated code at the end, check last 3 lines

    – TheSprinter
    Nov 16 '18 at 12:27











  • How about select? Can you show me how to implement select from all entities?

    – Peter Penzov
    Nov 16 '18 at 12:42
















0














Its possible if you have relation between tables(risk_filters,risk_parameters & risk_details) i.e. primary key and foreign key relationship.



Suppose risk_filters has one to one relationship with risk_parameters & risk_details, then the Entity will be look like



@Entity
@Table(name = "risk_filters")
public class RiskFilters implements Serializable {

private static final long serialVersionUID = -31232741713890134L;

@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "id", unique = true, updatable = false, nullable = false)
private int id;

@Column(length = 4)
private Integer terminal_id;

@Column(length = 255)
private String filter_class;

@Column(name = "FILTER_SETTINGS", columnDefinition = "TEXT", length = 65535)
private String filter_settings;

@Column(length = 4)
private Integer position;

@Column(length = 4)
private Integer parent_id;

@Column
private LocalDateTime created_at;

@Column
private TemporalType updated_at;

@OneToOne
@JoinColumn(name="risk_filter_id", nullable=false)
private RiskParameters riskParameters;

@OneToOne
@JoinColumn(name="risk_filter_id", nullable=false)
private RiskDetails riskDetails;
.....
}


and the call save method to save only RiskFilters Entity as below.



riskFilterObject.setRiskDetails(riskDetailsObject);
riskFilterObject.setRiskParamarets(riskParametersObject);
repository.save(riskFilterObject);// update 3 tables
repository.save(riskDetailsObject); // update only risk_details table
repository.save(riskParametersObject);// update only risk_parameters table


Update:




How about select? Can you show me how to implement select from all
entities?




RiskFilters filters = riskFiltersRepository.findOne(id);
// for Complete netsed RiskFilters Entity object

RiskParameter param = riskParameterRepository.findOne(id);
// for only RiskParameter Entity object

RiskDetails details = riskDetailsRepository.findOne(id);
// for only RiskDetails Entity object






share|improve this answer


























  • Yes but I have filter with 2 and filter with 8 settings. I have to use different tables for different cases.

    – Peter Penzov
    Nov 16 '18 at 12:09













  • if you want to save R.Param & R.Details individually u can do that, it wont affect Risk_filter as we haven't mapped bidirectionally.

    – TheSprinter
    Nov 16 '18 at 12:13











  • Ok, can you show me JPA example using my entities in my original post?

    – Peter Penzov
    Nov 16 '18 at 12:23











  • updated code at the end, check last 3 lines

    – TheSprinter
    Nov 16 '18 at 12:27











  • How about select? Can you show me how to implement select from all entities?

    – Peter Penzov
    Nov 16 '18 at 12:42














0












0








0







Its possible if you have relation between tables(risk_filters,risk_parameters & risk_details) i.e. primary key and foreign key relationship.



Suppose risk_filters has one to one relationship with risk_parameters & risk_details, then the Entity will be look like



@Entity
@Table(name = "risk_filters")
public class RiskFilters implements Serializable {

private static final long serialVersionUID = -31232741713890134L;

@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "id", unique = true, updatable = false, nullable = false)
private int id;

@Column(length = 4)
private Integer terminal_id;

@Column(length = 255)
private String filter_class;

@Column(name = "FILTER_SETTINGS", columnDefinition = "TEXT", length = 65535)
private String filter_settings;

@Column(length = 4)
private Integer position;

@Column(length = 4)
private Integer parent_id;

@Column
private LocalDateTime created_at;

@Column
private TemporalType updated_at;

@OneToOne
@JoinColumn(name="risk_filter_id", nullable=false)
private RiskParameters riskParameters;

@OneToOne
@JoinColumn(name="risk_filter_id", nullable=false)
private RiskDetails riskDetails;
.....
}


and the call save method to save only RiskFilters Entity as below.



riskFilterObject.setRiskDetails(riskDetailsObject);
riskFilterObject.setRiskParamarets(riskParametersObject);
repository.save(riskFilterObject);// update 3 tables
repository.save(riskDetailsObject); // update only risk_details table
repository.save(riskParametersObject);// update only risk_parameters table


Update:




How about select? Can you show me how to implement select from all
entities?




RiskFilters filters = riskFiltersRepository.findOne(id);
// for Complete netsed RiskFilters Entity object

RiskParameter param = riskParameterRepository.findOne(id);
// for only RiskParameter Entity object

RiskDetails details = riskDetailsRepository.findOne(id);
// for only RiskDetails Entity object






share|improve this answer















Its possible if you have relation between tables(risk_filters,risk_parameters & risk_details) i.e. primary key and foreign key relationship.



Suppose risk_filters has one to one relationship with risk_parameters & risk_details, then the Entity will be look like



@Entity
@Table(name = "risk_filters")
public class RiskFilters implements Serializable {

private static final long serialVersionUID = -31232741713890134L;

@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "id", unique = true, updatable = false, nullable = false)
private int id;

@Column(length = 4)
private Integer terminal_id;

@Column(length = 255)
private String filter_class;

@Column(name = "FILTER_SETTINGS", columnDefinition = "TEXT", length = 65535)
private String filter_settings;

@Column(length = 4)
private Integer position;

@Column(length = 4)
private Integer parent_id;

@Column
private LocalDateTime created_at;

@Column
private TemporalType updated_at;

@OneToOne
@JoinColumn(name="risk_filter_id", nullable=false)
private RiskParameters riskParameters;

@OneToOne
@JoinColumn(name="risk_filter_id", nullable=false)
private RiskDetails riskDetails;
.....
}


and the call save method to save only RiskFilters Entity as below.



riskFilterObject.setRiskDetails(riskDetailsObject);
riskFilterObject.setRiskParamarets(riskParametersObject);
repository.save(riskFilterObject);// update 3 tables
repository.save(riskDetailsObject); // update only risk_details table
repository.save(riskParametersObject);// update only risk_parameters table


Update:




How about select? Can you show me how to implement select from all
entities?




RiskFilters filters = riskFiltersRepository.findOne(id);
// for Complete netsed RiskFilters Entity object

RiskParameter param = riskParameterRepository.findOne(id);
// for only RiskParameter Entity object

RiskDetails details = riskDetailsRepository.findOne(id);
// for only RiskDetails Entity object







share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 19 '18 at 10:57

























answered Nov 16 '18 at 12:04









TheSprinterTheSprinter

573316




573316













  • Yes but I have filter with 2 and filter with 8 settings. I have to use different tables for different cases.

    – Peter Penzov
    Nov 16 '18 at 12:09













  • if you want to save R.Param & R.Details individually u can do that, it wont affect Risk_filter as we haven't mapped bidirectionally.

    – TheSprinter
    Nov 16 '18 at 12:13











  • Ok, can you show me JPA example using my entities in my original post?

    – Peter Penzov
    Nov 16 '18 at 12:23











  • updated code at the end, check last 3 lines

    – TheSprinter
    Nov 16 '18 at 12:27











  • How about select? Can you show me how to implement select from all entities?

    – Peter Penzov
    Nov 16 '18 at 12:42



















  • Yes but I have filter with 2 and filter with 8 settings. I have to use different tables for different cases.

    – Peter Penzov
    Nov 16 '18 at 12:09













  • if you want to save R.Param & R.Details individually u can do that, it wont affect Risk_filter as we haven't mapped bidirectionally.

    – TheSprinter
    Nov 16 '18 at 12:13











  • Ok, can you show me JPA example using my entities in my original post?

    – Peter Penzov
    Nov 16 '18 at 12:23











  • updated code at the end, check last 3 lines

    – TheSprinter
    Nov 16 '18 at 12:27











  • How about select? Can you show me how to implement select from all entities?

    – Peter Penzov
    Nov 16 '18 at 12:42

















Yes but I have filter with 2 and filter with 8 settings. I have to use different tables for different cases.

– Peter Penzov
Nov 16 '18 at 12:09







Yes but I have filter with 2 and filter with 8 settings. I have to use different tables for different cases.

– Peter Penzov
Nov 16 '18 at 12:09















if you want to save R.Param & R.Details individually u can do that, it wont affect Risk_filter as we haven't mapped bidirectionally.

– TheSprinter
Nov 16 '18 at 12:13





if you want to save R.Param & R.Details individually u can do that, it wont affect Risk_filter as we haven't mapped bidirectionally.

– TheSprinter
Nov 16 '18 at 12:13













Ok, can you show me JPA example using my entities in my original post?

– Peter Penzov
Nov 16 '18 at 12:23





Ok, can you show me JPA example using my entities in my original post?

– Peter Penzov
Nov 16 '18 at 12:23













updated code at the end, check last 3 lines

– TheSprinter
Nov 16 '18 at 12:27





updated code at the end, check last 3 lines

– TheSprinter
Nov 16 '18 at 12:27













How about select? Can you show me how to implement select from all entities?

– Peter Penzov
Nov 16 '18 at 12:42





How about select? Can you show me how to implement select from all entities?

– Peter Penzov
Nov 16 '18 at 12:42




















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53336246%2finsert-data-in-several-table-using-single-jpa-query%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

List item for chat from Array inside array React Native

Thiostrepton

Caerphilly