Hi to all! I have problem.
I have JDO objects:
@PersistenceCapable(identityType = IdentityType.APPLICATION)
public class MenuButton {
@PrimaryKey
@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
private Long uid;
@Persistent
private String name;
@Persistent(mappedBy="menuButton")
private List<Topic> topicSets;
@Persistent
private boolean isEnabled;
@Persistent
private String toURL;
public Long getUid() {
return uid;
}
public void setUid(Long uid) {
this.uid = uid;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public List<Topic> getTopicSets() {
return topicSets;
}
public void setTopicSets(List<Topic> topicSets) {
this.topicSets = topicSets;
}
public boolean isEnabled() {
return isEnabled;
}
public void setEnabled(boolean isEnabled) {
this.isEnabled = isEnabled;
}
public String getToURL() {
return toURL;
}
public void setToURL(String toURL) {
this.toURL = toURL;
}
}
@PersistenceCapable(identityType = IdentityType.APPLICATION)
public class Topic {
@PrimaryKey
@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
private Key uid;
@Persistent
private MenuButton menuButton;
@Persistent
private String topicTheme;
@Persistent
private Text topicText;
public Key getUid() {
return uid;
}
public void setUid(Key uid) {
this.uid = uid;
}
public MenuButton getMenuButton() {
return menuButton;
}
public void setMenuButton(MenuButton menuButton) {
this.menuButton = menuButton;
}
public String getTopicTheme() {
return topicTheme;
}
public void setTopicTheme(String topicTheme) {
this.topicTheme = topicTheme;
}
public Text getTopicText() {
return topicText;
}
public void setTopicText(Text topicText) {
this.topicText = topicText;
}
}
I have Manager class to help me save or update data.
public class Manager {
PersistenceManager pm = null;
public Manager() {
pm = PMF.get().getPersistenceManager();
}
public PersistenceManager getPersistenceManager(){
return pm;
}
public boolean Save(Object obj) {
Transaction tx = null;
try {
tx = pm.currentTransaction();
tx.begin();
pm.makePersistent(obj);
tx.commit();
System.out.println("Успешно сохранили транзакцию!");
return true;
}
catch(Exception ex) {
System.out.println(ex.getMessage());
System.out.println(ex.getLocalizedMessage());
if(tx.isActive())
tx.rollback();
System.out.println("Откатили транзакцию по исключению");
return false;
}
}
public boolean Delete(Object obj){
Transaction tx = null;
try {
tx = pm.currentTransaction();
tx.begin();
pm.deletePersistent(obj);
tx.commit();
return true;
}
catch(Exception ex){
System.out.println(ex.getMessage());
return false;
}
finally {
if(tx.isActive())
tx.rollback();
}
}
public Object getObjects(Object obj) {
Query query = pm.newQuery(obj.getClass());
Object reObj = query.execute();
return reObj;
}
public Object getObjectById(Object obj, Long uid) {
Object reObj = pm.getObjectById(obj.getClass(), uid);
return reObj;
}
public Object executeJDOSQL(String sql){
Object reObj = pm.newQuery(sql).execute();
return reObj;
}
}
I servlet i do some:
String sql = String.format(
"select from %s where name == '%s'"
,MenuButton.class.getName()
,"Тесты");
MenuButton selBut =
((List<MenuButton>)mgr.executeJDOSQL(sql)).get
(0);
Topic topic = new Topic();
topic.setMenuButton(selBut);
topic.setTopicText(new Text("Какой то там текст!"));
topic.setTopicTheme("Какая то там тема");
System.out.println("Сохраняем");
if(!mgr.Save(topic))
System.out.println("Ошибка!");
It works OK!
I try do the same code on JSP page:
if(request.getContentLength() > 0) {
String theme = request.getParameter("themeTitle");
Text text = new Text(request.getParameter("themeBody"));
String sql = String.format(
"select from %s where name == '%s'"
,MenuButton.class.getName()
,"Тесты");
Manager mgr = new Manager();
MenuButton selBut =
((List<MenuButton>)mgr.executeJDOSQL(sql)).get
(0);
Topic topic = new Topic();
topic.setMenuButton(selBut);
topic.setTopicText(text);
topic.setTopicTheme(theme);
if(!mgr.Save(topic))
System.out.println("Ошибка!");
else System.out.println("Сохранил!");
}
It works without errors, but nothing in database save.
I can't understand where is my error!
--
You received this message because you are subscribed to the Google Groups
"Google App Engine for Java" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/google-appengine-java?hl=en.