首页 \ 问答 \ 使用Hibernate对多个属性进行动态查询(Dynamic Query on multiple properties with Hibernate)

使用Hibernate对多个属性进行动态查询(Dynamic Query on multiple properties with Hibernate)

我有一个有几个属性的模型。 属性可以是原始(String)或复杂(Object)。 用户可以对每个原始属性进行查询。 我想知道是否有一种简单的方法来动态构建查询。 我使用Java和Hibernate。

该模型

public class Model {
  String prop1;
  Point prop2;
  List<Shape> prop3;
}

PointShape是可以包含基元或对象的对象。 查询的示例将是prop1 =“A”且坐标为x = 3且y = 8并且其中一个形状为圆的所有实例。

prop1 =“A”和prop2.x = 3和prop2.y和prop3.get(i).type =“Circle”; 我们必须迭代prop3的所有实例。

我的第一个想法是不可维护和低效的。 它包括对所有基本属性进行查询,然后合并结果。

  • 获取prop1 =“A”的所有实例
  • 获取prop2.x = 3和prop3 = y的所有实例;
  • 获取其中一个Shape.type =“Circle”的所有实例;
  • 得到所有3集的交集

是否有任何现有的库或算法能够以更好(更聪明)的方式解决这个问题?

谢谢


I have a model that has several properties. The properties can be primitive (String) or complex (Object). The user can make a query on each primitive property. I would like to know if there is an easy way to build dynamically the query. I use Java and Hibernate.

The model

public class Model {
  String prop1;
  Point prop2;
  List<Shape> prop3;
}

Point and Shape are object that can contains primitives or objects. An example of a query would be all instances where prop1 = "A" and the coordinates are x = 3 and y = 8 and one of the shape is a circle.

prop1 = "A" and prop2.x = 3 and prop2.y and prop3.get(i).type = "Circle"; we would have to iterate on all instances of prop3.

My first idea was unmaintainable and inefficient. It consists in doing queries on all the primitive properties and then merge the results.

  • Get all instances where prop1 = "A"
  • Get all instances where prop2.x = 3 and prop3 = y;
  • Get all instances where one of the Shape.type = "Circle";
  • Get the intersection of all 3 sets

Is there any existing library or algorithm that can solve this problem in a better (smarter) way?

Thanks


原文:https://stackoverflow.com/questions/3463813
更新时间:2023-04-03 06:04

最满意答案

当我将其保存为.png文件时,我得到了更好的数字。

fig = plt.figure(figsize=(20, 222))
plt.subplots_adjust(top=.9, bottom=0.1, wspace=0.2, hspace=0.2)

for i in range(1, 65):

    print 'E', i, ':'

    plt.subplot(64, 2, i)
    plt.ylabel('E%s' % str(i))

    i += 1
    print E[0+j:127+j]
    plt.plot(E[0+j:127+j])
    j += 128
plt.savefig('foo.png', bbox_inches='tight')
plt.show()

虽然我相信有更好的解决方案。


I got a better figure when I saved it as .png file.

fig = plt.figure(figsize=(20, 222))
plt.subplots_adjust(top=.9, bottom=0.1, wspace=0.2, hspace=0.2)

for i in range(1, 65):

    print 'E', i, ':'

    plt.subplot(64, 2, i)
    plt.ylabel('E%s' % str(i))

    i += 1
    print E[0+j:127+j]
    plt.plot(E[0+j:127+j])
    j += 128
plt.savefig('foo.png', bbox_inches='tight')
plt.show()

Though I believe there is a better solution.

相关问答

更多
  • 这比我预想的要容易,我只是这样做了: pylab.subplot(4,4,10) ,它工作。 It was easier than I expected, I just did: pylab.subplot(4,4,10) and it worked.
  • 你可以使用gridspec和figure : import numpy as np import matplotlib.pyplot as plt from matplotlib import gridspec # generate some data x = np.arange(0, 10, 0.2) y = np.sin(x) # plot it fig = plt.figure(figsize=(8, 6)) gs = gridspec.GridSpec(1, 2, width_ratios= ...
  • 如果figure是一个Figure实例,你可以通过它获取其中的轴 allaxes = fig.get_axes() 这个( allaxes )的返回是图中所有轴的列表。 在此列表中,您需要从图中或其他来源了解哪个子图。 If figure is a Figure instance you can get the axes inside it via allaxes = fig.get_axes() The return of this (allaxes) is a list of all the axe ...
  • 首先,当您将Axes对象作为您的处置时,您正在使用调用plt 。 那条路会导致疼痛。 其次, imshow将轴刻度的纵横比设置为1.这就是为什么轴很窄的原因。 知道这一切,你的榜样变成: import numpy as np import matplotlib.pyplot as plt data = np.random.rand(10,4) #creating a wide figure with 2 subplots in 1 row fig, axes = plt.subplots(1, 2, f ...
  • _subplots是axes的子模块: https : //github.com/matplotlib/matplotlib/blob/master/lib/matplotlib/axes/_subplots.py 它不应被操纵,正如其领先的下划线所暗示的那样。 看一下源代码,我猜你的AxesSubplot是一个用subplot_class_factory创建的类。 _subplots is a submodule of axes: https://github.com/matplotlib/matplot ...
  • 当我将其保存为.png文件时,我得到了更好的数字。 fig = plt.figure(figsize=(20, 222)) plt.subplots_adjust(top=.9, bottom=0.1, wspace=0.2, hspace=0.2) for i in range(1, 65): print 'E', i, ':' plt.subplot(64, 2, i) plt.ylabel('E%s' % str(i)) i += 1 print E[0 ...
  • plt.*设置通常适用于matplotlib的当前图; 与plt.subplot ,你开始一个新的情节,因此设置不再适用于它。 你可以通过与图表相关联的Axes对象( 见这里的例子 )共享标签,蜱等,但是恕我直言,这会在这里矫枉过正。 相反,我会建议将常用的“样式”放入一个函数中,并根据每个图表调用它: def applyPlotStyle(): plt.xlabel('Size') plt.ylabel('Time(s)'); plt.title('Matrix multiplic ...
  • plt.subplot返回一个子对象,它是一种plt.subplot对象。 它有两种添加轴标签的方法: set_xlabel和set_ylabel : ax = plt.subplot('111') ax.set_xlabel('X Axis') ax.set_ylabel('Y Axis') 您也可以调用plt.xlabel和plt.ylabel (就像您以前所做的那样),并指定要将标签应用到的轴。 ax = plt.subplot('111') plt.xlabel('X Axis', axes=ax ...
  • 如果使用GridSpec这可能会容易GridSpec : import numpy as np import matplotlib.pylab as pl import matplotlib.gridspec as gridspec # Create 2x2 sub plots gs = gridspec.GridSpec(2, 2) pl.figure() ax = pl.subplot(gs[0, 0]) # row 0, col 0 pl.plot([0,1]) ax = pl.subplot( ...
  • 当然,只要你重新定位它们后你就不会使用tight_layout (因此也tight_layout )(之前你可以安全地使用它)。 基本上,只需执行以下操作: import matplotlib.pyplot as plt # Create something similar to your pickled figure...... fig, (ax1, ax2) = plt.subplots(ncols=2) ax1.plot(range(10), 'r^-') ax1.set(title='Origin ...

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)