我有一个关于Hibernate的问题.
我想连接到数据库并获取有关表(其所有列及其元数据 - 数据类型,排序规则,索引,描述,键等)的信息,同时使用java运行时.
开发时我无权访问此数据库.java应用程序将安装在不知道它们是数据库的其他公司中.是否有可能使用Hibernate来实现这一目标?
我无法在xml中创建映射或使用注释,因为我不知道模式/表/列.
换句话说,也许:是否有可能在应用程序运行时创建xml映射?从这个xml文件创建对象,并在运行时从创建的对象中读取属性?
我希望这个问题现在更清楚了.
我使用PHP并使用名为Idiorm的ORM进行SQL调用.
请求可能如下所示:
$person = ORM::for_table('person')->create();
$person->name = $_POST['name'];
$person->age = $_POST['age'];
$person->save();
Run Code Online (Sandbox Code Playgroud)
它工作得很好,但它可能不安全反对SQL注入?解决这个问题的正确/最佳方法是什么?例?
我不是在寻找任何可以做任何花哨的查询的东西,使用最先进的C#搞笑业务来生成光滑的查询,自动将类映射到数据库表,或者任何必须由大量元数据工作的东西由开发人员配置.事实上,我希望ORM与我使用C#的事实无关.
相反,我希望能够执行简单的命令来执行基本的SQL任务,例如:
但是,这些中的每一个最好是提供字符串来提供表格:
connection = new ConnectionToSQLServer(connectionString);
database = connection.FindDatabase("MyDatabase");
foreach(Table table in database.Tables())
{
table.AddColumn("MyColumn", typeof(String), COLUMNS::NOT_NULL)
...
}
Run Code Online (Sandbox Code Playgroud)
在处理SQL和C#时,有什么类似的东西吗?我并不十分担心拥有一台表现最佳的设备.
嗨,我有同样的问题:与额外字段的多对多自我关系?但是我找不到答案:/我先尝试了ManyToOne和其他网站OneToMany ...但后来我无法使用类似的东西
public function hasFriend(User $user)
{
return $this->myFriends->contains($user);
}
Run Code Online (Sandbox Code Playgroud)
因为有一些这个问题:
This function is called, taking a User type $user variable and you then use the contains() function on $this->myFriends.
Run Code Online (Sandbox Code Playgroud)
$ this-> myFriends是一个请求的ArrayCollection(与User不同的类型)和关于contains()的doctrine文档:
The comparison of two elements is strict, that means not only the value but also the type must match.
Run Code Online (Sandbox Code Playgroud)
那么用额外的字段解决这个ManyToMany关系的最佳方法是什么?或者,如果我回去设置onetomany和manytoone关系,我怎么能修改hasFriend方法?例如,检查ID是否在ID的数组集合中.
编辑:我有这张桌子...我需要的是:1.选择我的朋友......和我的粉丝......检查我是不是和他在一起.(因为他可以和我成为朋友,我不必和他在一起......就像在推特上一样).我可以做很多事,但我需要额外的字段,如:"查看""他订阅我的时间",你可以在我的桌子上看到.
并进行这样的查询,然后能够在树枝检查if(app.user.hasFriend(follower)或类似的东西)
$qb = $this->createQueryBuilder('r')
->select('u')
->innerJoin('UserBundle:User', 'u')
->Where('r.friend_id=:id')
->setParameter('id', $id)
->orderBy('r.time', 'DESC')
->setMaxResults(50);
return $qb->getQuery()
->getResult();
Run Code Online (Sandbox Code Playgroud)

In my model are 3 entities(in real more than 3, but 3 is actually at this situation)
They all have relation many to many(Candidate can have may Vacancies and many Events, Vacancy ...candidates and... events.....).
If I update Candidate - good result.
if I update Vacancy - good result
BUT if I update Event I have org.hibernate.NonUniqueObjectException
It shows when I change collection of vacancy in Event. If I comment place, where I change vacancies of event …
在我将我的版本从4.4升级到4.9之后,我发现ORMLite已经弃用了一些方法:
与此同时,我使用ORMLite构建的系统已经很多了.任何人都可以建议我最新的ORMLite如何处理这两种情况?我似乎无法找到有关如何在4.9版本中使用2个函数的任何文档.
或者我应该完全替换ORMLite并回到更稳定的orm库(例如Hibernate - >如果我想使用它,它迫使我使用很多罐子).
谢谢
我正在Django写一个简单的游戏,所有的事情都是正确的,但突然......我遇到了以下错误:
我不知道这些代码有什么问题:
(test)alireza@alireza:~/test/test1$ python manage.py syncdb
Operations to perform:
Synchronize unmigrated apps: django_admin_bootstrapped, django_admin_bootstrapped_bootstrap3, crispy_forms
Apply all migrations: contenttypes, admin, auth, arosis, sessions
Synchronizing apps without migrations:
Creating tables...
Installing custom SQL...
Installing indexes...
Running migrations:
Applying arosis.0008_auto_20150212_0826...Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/home/alireza/test/lib/python3.4/site-packages/django/core/management/__init__.py", line 385, in execute_from_command_line
utility.execute()
File "/home/alireza/test/lib/python3.4/site-
...
...
...
return self.to_python(value)
File "/home/alireza/test/lib/python3.4/site-packages/django/db/models/fields/__init__.py", line 1252, in to_python
params={'value': value},
django.core.exceptions.ValidationError: ["'' value …Run Code Online (Sandbox Code Playgroud) 我试图找到一种简单的方法来获取记录的id(用slug选择),这样我就可以用它来查询这条记录的子项(父/子相关).
$product = Products::where('url','the-slug')->get();
Run Code Online (Sandbox Code Playgroud)
现在我可以使用该集合来获取id并继续查询孩子们.
有更简单的方法吗?
和...
我可以单独用slug查询孩子吗?
在OneToMany我的实体类中添加两个关联似乎无效。如果我删除其中之一,效果很好。
@Entity
@Table(name = "school")
public class School {
private List<Teacher> teachers;
private List<Student> students;
@OneToMany(cascade=CascadeType.ALL, mappedBy = "school", fetch = FetchType.EAGER)
public List<Teacher> getTeachers()
return this.teachers;
}
public void setTeachers(List<Teacher> teachers) {
this.teachers = teachers;
}
@OneToMany(cascade=CascadeType.ALL, mappedBy = "school", fetch = FetchType.EAGER)
public List<Student> getStudents()
return this.students;
}
public void setStudents(List<Student> teachers) {
this.students = students;
}
}
Run Code Online (Sandbox Code Playgroud)
然后在Teacher,Student我有正确的ManyToOne注释
@Entity
@Table(name = "teacher")
public class Teacher {
private School school; …Run Code Online (Sandbox Code Playgroud) 我已经找到了两个这个和这个主题,但仍然无法填充到我的案例中.我有一个Account.我可以Payments从一个帐户到另一个帐户.出于这个目的,我想存储payer_account_id和receiver_account_id在Payments表中.如何使用Annotations进行映射?

@Entity
public class Account {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
private Double balance;
//mapping here to Payments Entity
private ???
}
@Entity
public class Payments {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
private Double ammount;
//mapping here to Account Entity
private Account payerAccount;
//mapping here to Account Entity
private Account receiverAccount;
}
Run Code Online (Sandbox Code Playgroud)