public class Main {
public static void main(String[] args) {
final double num1 = 10.14;
final double num2 = 11.142;
final double num3 = 13.1844;
final Double sum = (num1 + num2 + num3);
long result1 = Math.round(sum);
System.out.println(result1);
BigDecimal result2 = BigDecimal.valueOf(sum).setScale(0, RoundingMode.HALF_UP);
System.out.println(result2);
BigDecimal result3 = BigDecimal.valueOf(sum).round(new MathContext(2, RoundingMode.HALF_UP));
System.out.println(result3);
Long result4 = sum.longValue();
System.out.println(result4);
}
}
Create iOS Apps in Java
Port your existing Android App, or build a native Cross-Platform App from scratch
// сигнатуры методов могут отличаться
takeBook(); // взять книгу
returnBook(); // вернуть книгу
orderBook(); // заказать книгу
bringBook(); // принести книгу
findBook(); // найти книгу
overdueNotification(User reader); // уведомить о времени возврата
Reader implements iReader
Librarian implements iLibrarian
Supplier implements iSupplier
Admin implements iAdministrator
Admin implements iAdministrator, iReader
имплементируем нужный интерфейс тоже.Reader extends User implements iReader
interface iReader<T extends User>
Reader extends User implements iReader<Reader>
Вопрос: Это тупое решение? если да, то как правильно решить данную задачу?
{
"movies": [
{
"name": "Good omens",
"year": 2019,
"description": "TV Series",
"director": {
"fullName": "Douglas Mackinnon"
},
"cast": [
{
"fullName": "Michael Sheen",
"role": "Aziraphale"
},
{
"fullName": "David Tennant",
"role": "Crowley"
}
]
}
]
}
-----------------------------------com.example.Example.java-----------------------------------
public class Example {
@SerializedName("movies")
@Expose
public List<Movie> movies = null;
}
-----------------------------------com.example.Movie.java-----------------------------------
public class Movie {
@SerializedName("name")
@Expose
public String name;
@SerializedName("year")
@Expose
public Integer year;
@SerializedName("description")
@Expose
public String description;
@SerializedName("director")
@Expose
public Director director;
@SerializedName("cast")
@Expose
public List<Cast> cast = null;
}
-----------------------------------com.example.Director.java-----------------------------------
public class Director {
@SerializedName("fullName")
@Expose
public String fullName;
}
-----------------------------------com.example.Cast.java-----------------------------------
public class Cast {
@SerializedName("fullName")
@Expose
public String fullName;
@SerializedName("role")
@Expose
public String role;
}
@ManyToOne(fetch = FetchType.LAZY, optional = true)
@JoinColumn(name = "project_id", nullable = false)
@OnDelete(action = OnDeleteAction.CASCADE)
@JsonIgnore
private Project project;
delete()
и будет выброшено то исключение, которе вам нужно.
JPA does offer possibility to cascade operations (merge, persist, refresh, remove) to associated entities. Logic is in JPA and does not utilize database cascades.
There is no JPA standard compliant way to do cascades with database cascades.
There is no clean cut means to do this in JPA. The following will get you what you want... You can use CascadeType.DELETE, however this annotation only applies to the objects in the EntityManager, not the database. You want to be sure that ON DELETE CASCADE is added to the database constraint. To verify, you can configure JPA to generate a ddl file. Take a look at the ddl file, you'll notice that ON DELETE CASCADE is not part of the constraint. Add ON DELETE CASCADE to actual SQL in the ddl file, then update your database schema from the ddl. This will fix your problem .