- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Programmatische Erstellung von Data Source Einträgen
Hallo,
Wir versuchen in ein Data Source - Tabelle über Module-Code Daten zu schreiben. Die Tabelle hat eine 1-n Beziehung auf eine andere Tabelle. In die Haupttabelle zu schreiben hat mit folgender Code geklappt:
IDProvider requestsIDProvider = contentStore.getStoreElement("requests", IDProvider.UidType.CONTENTSTORE);
Content2 requestsContent2 = (Content2) requestsIDProvider;
Session requestsSession = requestsContent2.getSchema().getSession();
Entity newRequestEntity = requestsSession.createEntity(requestsContent2.getEntityType().getName());
...
requestsContent2.lock(newRequestEntity);
requestsContent2.setLock(true, false);
...
newRequestEntity.setValue("name",name);
||||| Einträge in zweite Tabelle (Contents) erstellen |||||
...
requestsSession.commit();
requestsContent2.save();
...
requestsContent2.unlock(newRequestEntity);
requestsContent2.setLock(false, false);
Jetzt will ich in die zweite, zusammenhängende 1-n Tabelle Einträge für einzelne Request-Einträge speichern. Ich habe versucht im Platzhalter von oben "||||| Einträge in zweite Tabelle (Contents) erstellen |||||" folgendes zu machen:
IDProvider contentsIDProvider = contentStore.getStoreElement("requests_contents", IDProvider.UidType.CONTENTSTORE);
Content2 contentsContent2 = (Content2) contentsIDProvider;
Session contentsSession = contentsContent2.getSchema().getSession();
List<Entity> contents = new ArrayList<Entity>();
for(String contentId : contentIds){
Entity newContentEntity = contentsSession.createEntity(contentsContent2.getEntityType().getName());
...
contentsContent2.lock(newContentEntity);
contentsContent2.setLock(true, false);
...
newContentEntity.setValue("contentId",contentId);
...
contentsSession.commit();
contentsContent2.save();
...
contentsContent2.unlock(newContentEntity);
contentsContent2.setLock(false, false);
contents.add(newContentEntity);
}
newRequestEntity.setValue("contents",contents);
Anscheinend geht das nicht. Value muss ein (de.espirit.or.impl.PersistentList) sein. Ich weiss aber nicht ich eine PersistentList intanzieren kann. Ist meine Vorgehensweise überhaupt korrekt? Vielen Dank!
Gruss,
Koray
- Labels:
-
Developers
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Ich habe eine andere Vorgehensweise angewendet und es hat geklappt. Statt in Haupttabelle Entity die Kind-Entitties als Array / PersistenList zu speichern habe ich in Kind-Tabelle ein Entity erstellt und Parent Entity in entsprechendes Feld als Value gespeichert:
||||| Einträge in zweite Tabelle (Contents) erstellen |||||
IDProvider contentsIDProvider = contentStore.getStoreElement("requests_contents", IDProvider.UidType.CONTENTSTORE);
Content2 contentsContent2 = (Content2) contentsIDProvider;
Session contentsSession =contentsContent2.getSchema().getSession();
for(String contentId : contentIds){
Entity newContentEntity =contentsSession.createEntity(contentsContent2.getEntityType().getName());
...
contentsContent2.lock(newContentEntity);
contentsContent2.setLock(true, false);
...
newContentEntity.setValue("contentId",contentId);
newContentEntity.setValue("requests", newRequestEntity);
...
contentsSession.commit();
contentsContent2.save();
...
contentsContent2.unlock(newContentEntity);
contentsContent2.setLock(false, false);
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Ich habe eine andere Vorgehensweise angewendet und es hat geklappt. Statt in Haupttabelle Entity die Kind-Entitties als Array / PersistenList zu speichern habe ich in Kind-Tabelle ein Entity erstellt und Parent Entity in entsprechendes Feld als Value gespeichert:
||||| Einträge in zweite Tabelle (Contents) erstellen |||||
IDProvider contentsIDProvider = contentStore.getStoreElement("requests_contents", IDProvider.UidType.CONTENTSTORE);
Content2 contentsContent2 = (Content2) contentsIDProvider;
Session contentsSession =contentsContent2.getSchema().getSession();
for(String contentId : contentIds){
Entity newContentEntity =contentsSession.createEntity(contentsContent2.getEntityType().getName());
...
contentsContent2.lock(newContentEntity);
contentsContent2.setLock(true, false);
...
newContentEntity.setValue("contentId",contentId);
newContentEntity.setValue("requests", newRequestEntity);
...
contentsSession.commit();
contentsContent2.save();
...
contentsContent2.unlock(newContentEntity);
contentsContent2.setLock(false, false);
}

