com.avaje.ebean.Ebean.save()方法的使用及代码示例

x33g5p2x  于2022-01-19 转载在 其他  
字(1.9k)|赞(0)|评价(0)|浏览(129)

本文整理了Java中com.avaje.ebean.Ebean.save()方法的一些代码示例,展示了Ebean.save()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Ebean.save()方法的具体详情如下:
包路径:com.avaje.ebean.Ebean
类名称:Ebean
方法名:save

Ebean.save介绍

[英]Either Insert or Update the bean depending on its state.

If there is no current transaction one will be created and committed for you automatically.

Save can cascade along relationships. For this to happen you need to specify a cascade of CascadeType.ALL or CascadeType.PERSIST on the OneToMany, OneToOne or ManyToMany annotation.

In this example below the details property has a CascadeType.ALL set so saving an order will also save all its details.

public class Order { ...OneToMany(cascade=CascadeType.ALL, mappedBy="order") 
List details; 
... 
} 
}

When a save cascades via a OneToMany or ManyToMany Ebean will automatically set the 'parent' object to the 'detail' object. In the example below in saving the order and cascade saving the order details the 'parent' order will be set against each order detail when it is saved.
[中]根据bean的状态插入或更新bean。
如果没有当前事务,将自动为您创建并提交一个事务。
保存可以沿关系级联。要实现这一点,您需要指定级联类型的级联。全部或级联类型。坚持使用一对一、一对一或多对多的注释。
在下面的示例中,details属性具有级联类型。所有设置,因此保存订单也将保存其所有详细信息。

public class Order { ...OneToMany(cascade=CascadeType.ALL, mappedBy="order") 
List details; 
... 
} 
}

当通过一个一个或多个存储级联时,Ebean将自动将“父”对象设置为“细节”对象。在下面的示例中,在保存订单和级联保存订单详细信息时,将针对每个订单详细信息设置“父”订单。

代码示例

代码示例来源:origin: com.typesafe.play/play-java-ebean

/**
 * Saves (inserts) this entity.
 */
public void save() {
  Ebean.save(this);
}

代码示例来源:origin: org.avaje.ebeanorm/avaje-ebeanorm-api

/**
 * Save all the beans from a Collection.
 */
public static int save(Collection<?> c) throws OptimisticLockException {
 return save(c.iterator());
}

代码示例来源:origin: org.avaje/ebean

/**
 * Save all the beans from a Collection.
 */
public static int save(Collection<?> c) throws OptimisticLockException {
  return save(c.iterator());
}

代码示例来源:origin: MrNeuronix/IRISv2

@Override
public synchronized void save()
{
  if (this.getId() == null)
  {
    Ebean.save(this);
  }
  else
  {
    Ebean.update(this);
  }
}

相关文章