I have 2 tables parent and child, parent as 1 Primary Key and a composite unique key(Combination of 2 columns[UN_KEY1, UN_KEY2]) . Now in the child table i refer these 2 columns as foreign keys. When i try to generate the entity in eclipse it show Many to one relationship and displays the parent columns. But when i generate these two columns are not generated in the Parent Entity. How to do transaction like add, update, delete in these entity without those columns
Table
--drop table "TBL_PARENT";
CREATE TABLE "TBL_PARENT"(
"S_ID" INTEGER NOT NULL GENERATED ALWAYS AS IDENTITY(START WITH 1, INCREMENT BY 1, NO MINVALUE, NO MAXVALUE, CACHE 20),
"UN_KEY1" Integer NOT NULL,
"UN_KEY2" Smallint NOT NULL,
"SOME_COL1" Integer
);
-- Add keys for table TBL_PARENT
ALTER TABLE "TBL_PARENT" ADD CONSTRAINT "TBL_PARENTKEY3" PRIMARY KEY ("S_ID");
ALTER TABLE "TBL_PARENT" ADD CONSTRAINT "TBL_PARENTKey4" UNIQUE ("UN_KEY1","UN_KEY2");
--drop table "TBL_PARENT";
CREATE TABLE "TBL_CHILD"(
"S_ID" Integer NOT NULL GENERATED ALWAYS AS IDENTITY(START WITH 1, INCREMENT BY 1, NO MINVALUE, NO MAXVALUE, CACHE 20),
"UN_KEY1" Integer,
"UN_KEY2" Integer,
"SOME_COL2" Integer
);
ALTER TABLE "TBL_CHILD" ADD CONSTRAINT "TBL_CHILD_KEY3" PRIMARY KEY ("S_ID");
ALTER TABLE "TBL_CHILD" ADD CONSTRAINT "TBL_CHILD_FK" FOREIGN KEY ("UN_KEY1", "UN_KEY2") REFERENCES "TBL_PARENT" ("UN_KEY1", "UN_KEY2");
Generated Code:
#Entity
#Table(name="TBL_PARENT")
#NamedQuery(name="TblParent.findAll", query="SELECT t FROM TblParent t")
public class TblParent implements Serializable {
private static final long serialVersionUID = 1L;
#Id
#Column(name="S_ID")
private int sId;
#Column(name="SOME_COL1")
private int someCol1;
//bi-directional many-to-one association to TblChild
#OneToMany(mappedBy="tblParent")
private Set<TblChild> tblChilds;
public TblParent() {
}
public int getSId() {
return this.sId;
}
public void setSId(int sId) {
this.sId = sId;
}
public int getSomeCol1() {
return this.someCol1;
}
public void setSomeCol1(int someCol1) {
this.someCol1 = someCol1;
}
public Set<TblChild> getTblChilds() {
return this.tblChilds;
}
public void setTblChilds(Set<TblChild> tblChilds) {
this.tblChilds = tblChilds;
}
public TblChild addTblChild(TblChild tblChild) {
getTblChilds().add(tblChild);
tblChild.setTblParent(this);
return tblChild;
}
public TblChild removeTblChild(TblChild tblChild) {
getTblChilds().remove(tblChild);
tblChild.setTblParent(null);
return tblChild;
}
}
#Entity
#Table(name="TBL_CHILD")
#NamedQuery(name="TblChild.findAll", query="SELECT t FROM TblChild t")
public class TblChild implements Serializable {
private static final long serialVersionUID = 1L;
#Id
#Column(name="S_ID")
private int sId;
#Column(name="SOME_COL2")
private int someCol2;
//bi-directional many-to-one association to TblParent
#ManyToOne
#JoinColumns({
#JoinColumn(name="UN_KEY1", referencedColumnName="UN_KEY1"),
#JoinColumn(name="UN_KEY2", referencedColumnName="UN_KEY2")
})
private TblParent tblParent;
public TblChild() {
}
public int getSId() {
return this.sId;
}
public void setSId(int sId) {
this.sId = sId;
}
public int getSomeCol2() {
return this.someCol2;
}
public void setSomeCol2(int someCol2) {
this.someCol2 = someCol2;
}
public TblParent getTblParent() {
return this.tblParent;
}
public void setTblParent(TblParent tblParent) {
this.tblParent = tblParent;
}
}
Add the following to TblParent object
#Column(name = "UN_KEY1")
private int uniqueKey1;
#Column(name = "UN_KEY2")
private int uniqueKey2;
When creating a new object you will be doing the following
TblParent p = new TblParent();
p.setSId(1);
p.setSomeCol1(12);
p.setUniqueKey1(12);
p.setUniqueKey2(14);
p.setTblChilds(new HashSet<TblChild>());
TblChild c = new TblChild();
c.setSId(1);
c.setSomeCol2(14);
c.setTblParent(p);
p.getTblChilds.add(c);
When you create this parent object the framework will automatically add the foreign key values to TblChild table.
Related
I learned that in Spring Data JDBC I need to implement many to many relationships by having a reference to the ID of one entity in the other entity:
public class Student {
#Id
private Long studentId;
private String studentName;
#MappedCollection(idColumn = "student_id", keyColumn = "course_id")
private Set<CourseRef> courses;
}
public class Course {
#Id
private Long courseId;
private String courseName;
}
#Table("student_course")
public class CourseRef {
#Id
private Long studentCourseId;
private Long courseId;
#MappedCollection(idColumn = "student_course_id", keyColumn = "test_score_id")
private List<TestScore> testScores;
}
public class TestScore {
#Id
private Long testScoreId;
private Integer value;
}
public interface StudentRepository implements CrudRepository<Student, Long> {
}
public interface CourseRepository implements CrudRepository<Course, Long> {
}
public class StudentRepositoryTest {
#Autowired
StudentRepository repository;
#Test
void testAddTestScore() {
Student student = repository.findById(1L).get();
assertNotNull(student);
Set<CourseRef> courses = student.getCourses();
CourseRef course = courses.stream().filter(c -> c.getCourseId() == 2).findFirst().orElse(null);
assertNotNull(course);
courses.remove(course);
course.addTestScore(TestScore.create(90);
courses.add(course);
students.setCourses(courses);
repository.save(student);
}
}
With this setup I have a student table, course table, student_course table, and test_score table that has a foreign key to a student_course id. But I'm having trouble adding a new test score. The repository is unable to save the updated student due to a foreign key constraint failure with the student_course_id column. I was wondering, is it possible to add new test scores with this approach, and if so would I need to create a new repository?
You didn't post your schema so I don't know what exactly went wrong, but I started with your code and created a working example from it: https://github.com/schauder/stackoverflow/tree/main/jdbc/three-way-reference
I took the liberty to simplify your property/column names since repeating the entity/table didn't add value for me.
The Domain Model
I put some hints of DDD on it, but didn't go the full 9 yards.
But I wanted at least to give some examples on how the logic for adding a TestScore belongs into the aggregate and not out side in the test or service. But this is not relevant for the mapping.
The important changes I made are:
I dropped the ids of CourseRef and TestScore. Ids in general are not neccesary on inner entities (not aggregate roots).
I had to reintroduce it to CourseRef due to a bug I found in the progress.
I simplified the code for adding a TestScore removing and then adding the course again is not necessary.
public class Course {
#Id
Long id;
String name;
static Course create(String name) {
Course course = new Course();
course.name = name;
return course;
}
}
class Student {
#Id
final Long id;
String name;
#MappedCollection(idColumn = "STUDENT_ID", keyColumn = "COURSE_ID")
Set<CourseRef> courses = new HashSet<>();
Student(Long id) {
this.id = id;
}
/**
* quality of life method to create students by name.
*/
public static Student create(String name) {
final Student student = new Student(null);
student.name = name;
return student;
}
/**
* The aggregate root should take care of whatever logic is necessary to add a course.
*/
void addCourse(Course course) {
final CourseRef ref = new CourseRef();
ref.courseId = AggregateReference.to(course.id);
courses.add(ref);
}
/**
* The aggregate root should take care of whatever logic is necessary to add a testscore.
* #param course
* #param score
*/
public void addScore(Course course, int score) {
courses.stream()
.filter(c -> c.courseId.getId().equals(course.id))
.findFirst()
.orElseThrow()
.testScores.add(TestScore.create(90));
}
}
#Table("STUDENT_COURSE")
class CourseRef {
#Id // work around for issue https://github.com/spring-projects/spring-data-jdbc/issues/1139
Long Id;
AggregateReference<Course,Long> courseId;
#MappedCollection(idColumn = "STUDENT_COURSE_ID", keyColumn = "INDEX")
List<TestScore> testScores;
}
class TestScore {
private Integer value;
public static TestScore create(int value) {
final TestScore testScore = new TestScore();
testScore.value = value;
return testScore;
}
}
Database Schema
I added one:
CREATE TABLE COURSE
(
ID INTEGER IDENTITY PRIMARY KEY,
NAME VARCHAR(200) NOT NULL
);
CREATE TABLE STUDENT
(
ID INTEGER IDENTITY PRIMARY KEY,
NAME VARCHAR(200) NOT NULL
);
CREATE TABLE STUDENT_COURSE
(
ID INTEGER IDENTITY PRIMARY KEY,
STUDENT_ID INTEGER NOT NULL,
COURSE_ID INTEGER NOT NULL,
UNIQUE (STUDENT_ID, COURSE_ID),
FOREIGN KEY (STUDENT_ID) REFERENCES STUDENT(ID),
FOREIGN KEY (COURSE_ID) REFERENCES COURSE(ID)
);
CREATE TABLE TEST_SCORE
(
STUDENT_COURSE_ID INTEGER,
INDEX INTEGER,
VALUE INTEGER,
PRIMARY KEY (STUDENT_COURSE_ID, INDEX),
FOREIGN KEY (STUDENT_COURSE_ID) REFERENCES STUDENT_COURSE(ID)
);
The Test
#DataJdbcTest
class StudentRepositoryTest {
#Autowired
StudentRepository students;
#Autowired
CourseRepository courses;
Student jens = null;
#BeforeEach
void setup() {
Course physics = courses.save(Course.create("Physics"));
Course math = courses.save(Course.create("Math"));
Course informatics = courses.save(Course.create("Informatics"));
jens = Student.create("Jens");
jens.addCourse(physics);
jens.addCourse(math);
jens.addCourse(informatics);
jens = students.save(jens);
}
#Test
void testAddTestScore() {
Student student = students.findById(jens.id).orElseThrow();
assertNotNull(student);
Course math = courses.findByName("Math");
assertNotNull(math);
student.addScore(math, 90);
students.save(student);
}
}
I'm currently working on a project where I'm trying to get a list of enities from table which does not have a primary key (dk_systemtherapie_merkmale). This table is 1:n related to another table (dk_systemtherapie). See the screenshot for the table structure.
When getting an entry for dk_systemtherapie, the program fetches the Collection "dkSystemtherapieMerkmalesById". However, the first table entry is fetched as often as the number of actual entries in the table is. It never fetches the other entries from dk_systemtherapie_merkmale. I assume it has something to do with the fact that hibernate can't differ between the entries, but I don't know how to fix it.
Table schema
I've created two corresponding entity classes, dk_systemtherapie:
#Entity
#Table(name = "dk_systemtherapie", schema = "***", catalog = "")
public class DkSystemtherapieEntity {
private int id;
private Collection<DkSystemtherapieMerkmaleEntity> dkSystemtherapieMerkmalesById;
#Id
#Column(name = "id")
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
#OneToMany(mappedBy = "dkSystemtherapieByEintragId")
public Collection<DkSystemtherapieMerkmaleEntity> getDkSystemtherapieMerkmalesById() {
return dkSystemtherapieMerkmalesById;
}
public void setDkSystemtherapieMerkmalesById(Collection<DkSystemtherapieMerkmaleEntity> dkSystemtherapieMerkmalesById) {
this.dkSystemtherapieMerkmalesById = dkSystemtherapieMerkmalesById;
}
}
Here the second one, which is accessing the table without a primary key, dk_systhemtherapie_merkmale:
#Entity #IdClass(DkSystemtherapieMerkmaleEntity.class)
#Table(name = "dk_systemtherapie_merkmale", schema = "***", catalog = "")
public class DkSystemtherapieMerkmaleEntity implements Serializable {
#Id private Integer eintragId;
#Id private String feldname;
#Id private String feldwert;
private DkSystemtherapieEntity dkSystemtherapieByEintragId;
#Basic
#Column(name = "eintrag_id")
public Integer getEintragId() {
return eintragId;
}
public void setEintragId(Integer eintragId) {
this.eintragId = eintragId;
}
#Basic
#Column(name = "feldname")
public String getFeldname() {
return feldname;
}
public void setFeldname(String feldname) {
this.feldname = feldname;
}
#Basic
#Column(name = "feldwert")
public String getFeldwert() {
return feldwert;
}
public void setFeldwert(String feldwert) {
this.feldwert = feldwert;
}
#Id
#ManyToOne
#JoinColumn(name = "eintrag_id", referencedColumnName = "id")
public DkSystemtherapieEntity getDkSystemtherapieByEintragId() {
return dkSystemtherapieByEintragId;
}
public void setDkSystemtherapieByEintragId(DkSystemtherapieEntity dkSystemtherapieByEintragId) {
this.dkSystemtherapieByEintragId = dkSystemtherapieByEintragId;
}
}
I assume the problem is releated to the fact that Hibernate is using the following annotation as the one and only id for fetching data from database.
#Id
#ManyToOne
#JoinColumn(name = "eintrag_id", referencedColumnName = "id")
public DkSystemtherapieEntity getDkSystemtherapieByEintragId() {
return dkSystemtherapieByEintragId;
}
This leads to the problem that when getting more than one entry with the same id (as the id is not unique), you will get the number of entries you would like to but hibernate is always fetching the first entry for this id. So in fact you are getting dublicate entries.
So how to fix this?
According to this question: Hibernate and no PK, there are two workarounds which are actually only working when you don't have NULL entries in your table (otherwise the returning object will be NULL as well) and no 1:n relationship. For my understanding, hibernate is not supporting entities on tables without primary key (documentation). To make sure getting the correct results, I would suggest using NativeQuery.
Remove the Annotations and private DkSystemtherapieEntity dkSystemtherapieByEintragId; (incl. beans) from DkSystemtherapieMerkmaleEntity.java und add a constructor.
public class DkSystemtherapieMerkmaleEntity {
private Integer eintragId;
private String feldname;
private String feldwert;
public DkSystemtherapieMerkmaleEntity(Integer eintragId, String feldname, String feldwert) {
this.eintragId = eintragId;
this.feldname = feldname;
this.feldwert = feldwert;
}
public Integer getEintragId() {
return eintragId;
}
public void setEintragId(Integer eintragId) {
this.eintragId = eintragId;
}
public String getFeldname() {
return feldname;
}
public void setFeldname(String feldname) {
this.feldname = feldname;
}
public String getFeldwert() {
return feldwert;
}
public void setFeldwert(String feldwert) {
this.feldwert = feldwert;
}
}
Remove private Collection<DkSystemtherapieMerkmaleEntity> dkSystemtherapieMerkmalesById; (incl. beans) from DkSystemtherapieEntity.java.
Always when you need to get entries for a particular eintrag_id, use the following method instead of the Collection in DkSystemtherapieEntity.java.
public List<DkSystemtherapieMerkmaleEntity> getDkSystemtherapieMerkmaleEntities(int id) {
Transaction tx = session.beginTransaction();
String sql = "SELECT * FROM dk_systemtherapie_merkmale WHERE eintrag_id =:id";
List<Object[]> resultList;
resultList = session.createNativeQuery(sql)
.addScalar("eintrag_id", IntegerType.INSTANCE)
.addScalar("feldname", StringType.INSTANCE)
.addScalar("feldwert", StringType.INSTANCE)
.setParameter("id", id).getResultList();
tx.commit();
List<DkSystemtherapieMerkmaleEntity> merkmale = new ArrayList<>();
for (Object[] o : resultList) {
merkmale.add(new DkSystemtherapieMerkmaleEntity((Integer) o[0], (String) o[1], (String) o[2]));
}
return merkmale;
}
Call getDkSystemtherapieMerkmaleEntities(dkSystemtherapieEntityObject.getid()) instead of getDkSystemtherapieMerkmalesById().
I'm just start to learning this ORM, so maybe I've done something wrong. In entity I write OneToOne relation but greendao doesn't generate it. If I'm writing in entity constructor arguments for foreign key it just ignores this and makes it like this. So there is no property and column in table. Thank you.
Public:
#Entity(active = true)
public class Public {
#Id(autoincrement = true)
Long id;
int publicId;
#ToOne(joinProperty = "id")
private Category category; ...
#Generated(hash = 12945501)
public Public(Long id, int publicId) {
this.id = id;
this.publicId = publicId;
}
PublicDao:
public class PublicDao extends AbstractDao<Public, Long> {
public static final String TABLENAME = "PUBLIC";
/**
* Properties of entity Public.<br/>
* Can be used for QueryBuilder and for referencing column names.
*/
public static class Properties {
public final static Property Id = new Property(0, Long.class, "id", true, "_id");
public final static Property PublicId = new Property(1, int.class, "publicId", false, "PUBLIC_ID");
} ...
/** Creates the underlying database table. */
public static void createTable(Database db, boolean ifNotExists) {
String constraint = ifNotExists? "IF NOT EXISTS ": "";
db.execSQL("CREATE TABLE " + constraint + "\"PUBLIC\" (" + //
"\"_id\" INTEGER PRIMARY KEY AUTOINCREMENT ," + // 0: id
"\"PUBLIC_ID\" INTEGER NOT NULL );"); // 1: publicId
}
My mistake. I should to add another field for it, and to write it in joinProperty.
I'm starting to use JPA with the OpenJPA API, and i'm having a problem with the find().
Here are the tables:
CREATE TABLE compania (
ID int(11) NOT NULL,
NOMBRE varchar(45) DEFAULT NULL,
PRIMARY KEY (ID)
)
CREATE TABLE modelo (
ID int(11) NOT NULL,
ID_COMPANIA int(11) DEFAULT NULL,
NOMBRE_MODELO varchar(45) DEFAULT NULL,
PRIMARY KEY (ID),
KEY MODELO_COMPANIA_FK_idx (ID_COMPANIA),
CONSTRAINT MODELO_COMPANIA_FK FOREIGN KEY (ID_COMPANIA) REFERENCES compania (ID)
)
and here are my Entities:
#Entity
public class Compania extends EntityJPA{
private static final long serialVersionUID = 1L;
#Id
private int id;
#Column
private String nombre;
#OneToMany(mappedBy="compania",cascade={CascadeType.ALL})
#JoinColumn(name="ID_COMPANIA", nullable=false)
private List<Modelo> listaModelos;
public Compania() {
}
public int getId() {
return id;
}
public void setId(int idCompania) {
this.id = idCompania;
}
public String getNombre() {
return nombre;
}
public void setNombre(String nombreCompania) {
this.nombre = nombreCompania;
}
public List<Modelo> getListaModelos() {
return listaModelos;
}
public void setListaModelos(List<Modelo> listaModelos) {
this.listaModelos = listaModelos;
}
}
#Entity
public class Modelo extends EntityJPA{
private static final long serialVersionUID = 1L;
#Id
#GeneratedValue(strategy=GenerationType.IDENTITY)
private int id;
#Column(name="NOMBRE_MODELO")
private String nombreModelo;
#ManyToOne
#JoinColumn(name="ID_COMPANIA", referencedColumnName="ID")
private Compania compania;
public Modelo() {
}
public Compania getCompania() {
return compania;
}
public void setCompania(Compania compania) {
this.compania = compania;
}
public int getId() {
return id;
}
public void setId(int idModelo) {
this.id = idModelo;
}
public String getNombre() {
return nombreModelo;
}
public void setNombre(String nombreModelo) {
this.nombreModelo = nombreModelo;
}
}
At the moment I make the
Compania cia = getEntityManager().find(Compania.class, idCompania);
the cia object does not have the value of the #Id attribute, it has the value of nombre but not of id. I mean:
cia.getId() = 0
and it must be 1 or 2 , etc. Not 0.
Thank you very much for your help.
I do not have the code to persist because It was already persisted.
the code for the find is
public static Compania findCompania(int idCompania){
try {
Compania cia = getEntityManager().find(Compania.class, idCompania);
return cia;
} finally {
closeEntityManager();
}
}
And if I activate the log, this is the select it shows:
482 testMySql TRACE [http-bio-8080-exec-5] openjpa.jdbc.SQL - <t 1228180882, conn 1699837157> executing prepstmnt 2127861376 SELECT t0.nombre FROM Compania t0 WHERE t0.id = ? [params=(int) 1]
497 testMySql TRACE [http-bio-8080-exec-5] openjpa.jdbc.SQL - <t 1228180882, conn 1699837157> [15 ms] spent
As you can see, there is no t0.id in the select.
Thanks for your help.
Primary Key (ID) not retrieved (?) from database using OpenJPA
Duplicate.... the net of the post is that you need to use a different enhancement method.
If you don't specifically set the value for the #Id attribute you have to declare it with #GeneratedValueso that it's automatically incremented.
So I reverse engineered some tables from my db and when I try to save my object to the db I get the following error:
Initial SessionFactory creation failed.org.hibernate.AnnotationException: A Foreign key refering com.mycode.Block from com.mycode.Account has the wrong number of column. should be 2
Exception in thread "main" java.lang.ExceptionInInitializerError
The Domain objects Are Block which contains a number of Account Objects:
#OneToMany(fetch = FetchType.LAZY, mappedBy = "Block")
public Set<EAccount> getAccounts() {
return this.Accounts;
}
Account has a Composite key of Id and Role. This has been setup in a seperate Class:
#Embeddable
public class BlockAccountId implements java.io.Serializable {
private long blockOid;
private String accountRole;
public BlockAccountId() {
}
public BlockAccountId(long blockOid, String accountRole) {
this.blockOid = blockOid;
this.accountRole = accountRole;
}
#Column(name = "BLOCK_OID", nullable = false)
public long getBlockOid() {
return this.blockOid;
}
public void setBlockOid(long blockOid) {
this.blockOid = blockOid;
}
#Column(name = "ACCOUNT_ROLE", nullable = false, length = 10)
public String getAccountRole() {
return this.accountRole;
}
public void setAccountRole(String accountRole) {
this.accountRole = accountRole;
}
So I want to know. How can I Link the tables Block and account on blockOid but still ensure the account table has both blockOid and accountRole as a composite key.
Any examples would be greatly appreciated!
N.B this is a Block (One) to Account (Many) relationship.
Thanks
The easiest is to place your association directly in the embedded id component.
Hibernate reference documentation
Section 5.1.2.1.1. id as a property using a component type ()
Example (Only write the important getter() and setter())
#Entity
public class Block {
#Id
#GeneratedValue(strategy = GenerationType.IDENTITY)
#Column(name="BLOCK_OID")
long blockOid;
#OneToMany(fetch = FetchType.LAZY, mappedBy = "id.block", cascade=CascadeType.ALL)
Set<Account> accounts = new HashSet<Account>();
}
#Entity
public class Account {
#EmbeddedId BlockAccountId id;
public Account()
{
this.id = new BlockAccountId();
}
public void setBlock(Block pBlock) {
this.id.setBlock(pBlock);
}
public Block getBlock() {
return this.id.getBlock();
}
public String getAccountRole() {
return this.id.getAccountRole();
}
public void setAccountRole(String accountRole) {
this.id.setAccountRole(accountRole);
}
}
#Embeddable
public class BlockAccountId implements java.io.Serializable {
#ManyToOne(optional = false)
private Block block;
#Column(name = "ACCOUNT_ROLE", nullable = false, length = 10)
private String accountRole;
public BlockAccountId() {
}
//Implement equals and hashcode
}
The corresponding database table are :
CREATE TABLE block (
BLOCK_OID bigint(20) NOT NULL auto_increment,
PRIMARY KEY (`BLOCK_OID`)
)
CREATE TABLE account (
ACCOUNT_ROLE varchar(10) NOT NULL,
block_BLOCK_OID bigint(20) NOT NULL,
PRIMARY KEY (`ACCOUNT_ROLE`,`block_BLOCK_OID`),
KEY `FK_block_OID` (`block_BLOCK_OID`),
CONSTRAINT `FK_block_OID` FOREIGN KEY (`block_BLOCK_OID`) REFERENCES `block` (`BLOCK_OID`)
)
based on hibernate documentation here's the link
based on it you can do the following :
#Entity
public class Account {
#EmbeddedId BlockAccountId id;
#MapsId(value = "blockOid")
#ManyToOne
private Block block;
public Account()
{
this.id = new BlockAccountId();
}
public void setBlock(Block pBlock) {
this.block = pBlock;
}
public Block getBlock() {
return this.block;
}
public String getAccountRole() {
return this.id.getAccountRole();
}
public void setAccountRole(String accountRole) {
this.id.setAccountRole(accountRole);
}
}