首页 \ 问答 \ MongoDB和Morphia - Traditionnal id(Long)而不是ObjectId(MongoDB and Morphia - Traditionnal id (Long) instead of ObjectId)

MongoDB和Morphia - Traditionnal id(Long)而不是ObjectId(MongoDB and Morphia - Traditionnal id (Long) instead of ObjectId)

背景:

我的REST服务项目是通过使用Hibernate启动的。 我在域类中使用id(Long)作为rest url中标识符的一部分,例如:

http://abc.com/customer-50 ,其中50是Long id。

Hibernate Annotated类如下:

public class Customer {
@Id
@GeneratedValue
private Long id;
}

现在我需要将我们的设计迁移到Mongodb。 自然的选择是使用Morphia,这是一个实体框架。

问题:在Morphia中,id字段是ObjectId

@Id private ObjectId id;

这将导致问题,因为:1。它不是自动增量,即http://abc.com/customer-50,http://abc.com/customer-51,http://abc.com/customer- 52

现在它变成了http://abc.com/customer-4d1b4687a6d5437619000000

  1. 我需要将所有引用类从long更改为objectId。

  2. 是否可以保留原始设计(使用Long id而不是ObjectId)?

谢谢!


Background:

My REST service project was started up by using Hibernate. I use id (Long) in domain class as part of the identifier in rest url, for example:

http://abc.com/customer-50, where 50 is the Long id.

The Hibernate Annotated class is as below:

public class Customer {
@Id
@GeneratedValue
private Long id;
}

Now I need to migrate our design to Mongodb. The natural choice is using Morphia, which is an entity framework.

Problem: In Morphia, the id field is ObjectId

@Id private ObjectId id;

This will cause problem because: 1. It is not auto-increment, i.e. http://abc.com/customer-50, http://abc.com/customer-51, http://abc.com/customer-52.

Now it become http://abc.com/customer-4d1b4687a6d5437619000000

  1. I will need to change all the reference classes from long to objectId.

  2. Is it possible to keep the original design (which uses Long id, instead of ObjectId)?

Thanks!


原文:https://stackoverflow.com/questions/8365572
更新时间:2024-02-06 13:02

最满意答案

您可以做的最好的事情是下载PhoneGap,将您的HTML5 / Sencha应用程序粘贴到新的PhoneGap应用程序的www目录中,使用XCode进行编译,以便您拥有一个为您的Sencha应用程序提供服务的本机PhoneGap应用程序。 然后,一旦你走得那么远,你可以创建一个加载外部应用程序的事件(例如,点击按钮等)。

PhoneGap提供了一个JavaScript入口点,您可以在Sencha开发中使用它。 您可以运行本机PhoneGap功能,包括PhoneGap的ChildBrowser插件(https://github.com/purplecabbage/phonegap-plugins/tree/master/iPhone/ChildBrowser)。 使用Sencha为PhoneGap的childbrowser插件调用JS入口点,并使用ChildBrowser加载外部应用程序。

你不能只做一个iframe的原因至少有三个:

  1. 有人抱怨说,在sencha应用程序中加载iframe已经破坏了Native中的应用程序。 (我想如果iframe包含一个复杂的网页,这可能会导致内存问题,这会导致应用程序崩溃。)
  2. 没有简单的方法来支持iframe中的滚动。 Sencha实现的基于JS的触摸滚动不会进入iframe。 (有可能让它与某种黑客一起工作,但你仍然有上面的问题#1。)
  3. 您可能在iframe内部调整内容时遇到问题,因此看起来不错。

我应该注意,为了完整起见,有些人在本网站上表示他们已经能够通过JSONP / AJAX加载网页,然后将页面的HTML注入他们的Sencha应用程序。 我怀疑这可能是一致的,因为它可以简单地在PhoneGap上使用一些并使用ChildBrowser插件。


The best thing you can do is download PhoneGap, stick your HTML5/Sencha app into the www directory of a new PhoneGap app, compile it with XCode so that you have a native PhoneGap app serving your Sencha app. Then, once you get that far, you can create an event for loading your external app (e.g., on a button click, etc.).

PhoneGap provides a JavaScript entry point that you can use within your Sencha development. You can run native PhoneGap functionality, including the ChildBrowser plugin for PhoneGap (https://github.com/purplecabbage/phonegap-plugins/tree/master/iPhone/ChildBrowser). Use Sencha to call the JS entry point for PhoneGap's childbrowser plugin, and use the ChildBrowser to load your external app.

The reasons you cannot just do an iframe are at least threefold:

  1. Some have complained that loading an iframe inside of a sencha app has crashed the app in Native. (I imagine if the iframe contains a complex webpage, this may cause a memory issue, which would cause the app to crash.)
  2. There is no easy way to support scrolling within the iframe. The JS-based touch scrolling that Sencha implements does not carry into the iframe. (It may be possible to get this to work with some kind of hack, but you'd still have problem #1 above.)
  3. You may have issues sizing your content inside of the iframe so that it looks decent.

I should note, for the sake of completeness, that some have indicated on this site that they've been able to load a webpage via JSONP / AJAX and then inject the HTML of the page into their Sencha app. I suspect this may be as complicated to get working consistently as it would be to simply bone up a bit on PhoneGap and use the ChildBrowser plugin.

相关问答

更多
  • Sencha touch对于那些用于网页设计的用户而言更为复杂,因为它几乎是一个纯粹的编程模型(您不用html设计页面,以编程方式向页面添加元素)。 然而,它有一个更丰富的小部件模型,并且比jQTouch更丰富(它也是更大)... JQTouch更容易在飞行中运行(您基本上是在单个页面上设计div的页面),但是,如果您打算拥有很多屏幕,则必须非常明智地将应用程序分解成多个页面或创建您的页面动态地在Javascript中(至少在很多版本的Android和iPhone 3G上)DOM操纵与很多页面往往是缓慢发生 ...
  • 根据我的经验,您的问题的答案与您引用的问题相同: 如何在WebKit浏览器上全屏显示Sencha Touch 2页面? 它总是对我有用。 但是,在处理未编译版本的应用程序时,我有时会遇到此配置错误。 以下问题显示了我得到的错误以及我如何设法解决它。 viewport autoMaximize导致超时等待window.innerHeight在iPhone上更改 希望这可以帮助 From my experience the answer to your question is the same as the q ...
  • 可能会生成错误,因为里面没有_all.scss 触摸\资源\主题\样式表\煎茶触摸\默认 _all.scss的内容是 @import 'core'; @import 'widgets'; 再次检查应用程序结构或手动创建_all.scss并查看它是否解决了问题。 The error might be generated because there's no _all.scss inside touch\resources\themes\stylesheets\sencha-touch\default Con ...
  • 这纯粹是我的错..在index.html中我添加了base.scss文件而不是添加base.css,这就是它引发错误的原因。我更新了我的index.html,现在它工作正常。 谢谢那些帮助过我的人 That is purely my fault .. In index.html I added base.scss file instead of adding base.css ,that is why it raising an error.I updated my index.html and now i ...
  • Steve,返回“不允许”错误,因为您的登录请求违反了浏览器的同源策略 (实际上它声明所有XhrHttpRequests必须转到最初加载页面的同一域)。 有些浏览器提供了暂时禁用此错误的方法(这可能适用于短期开发目的),但从长远来看,您需要将应用程序托管在与后端服务器相同的域中,或者考虑使用CORS或JSONP满足您的要求。 Steve, the "is not allowed" error is returned because your login request violates the browse ...
  • 关于Sencha Touch的互联网上没有太多信息。 他们的最新版本是Sencha Touch 2.几个月前我确实探索过这种替代方案(当时,他们仍然在版本1上)。 话虽这么说,让我尽可能多地回答你的问题。 Sencha Touch驱动的应用程序无法在您的Web浏览器中运行。 它们在您设计的每个平台上本机运行。 但是,他们使用集成在您App中的webkit引擎。 因此,启动您的应用程序将不会打开浏览器页面,但会在您的应用程序中运行您的应用程序(顺便说一下HTML5)。 他们网站上的初步搜索提到了SQL数据库。 ...
  • 您可以做的最好的事情是下载PhoneGap,将您的HTML5 / Sencha应用程序粘贴到新的PhoneGap应用程序的www目录中,使用XCode进行编译,以便您拥有一个为您的Sencha应用程序提供服务的本机PhoneGap应用程序。 然后,一旦你走得那么远,你可以创建一个加载外部应用程序的事件(例如,点击按钮等)。 PhoneGap提供了一个JavaScript入口点,您可以在Sencha开发中使用它。 您可以运行本机PhoneGap功能,包括PhoneGap的ChildBrowser插件(http ...
  • Sencha touch是使用ExtJS进行跨平台开发的一个很好的框架。 您可以使用javascript开发应用程序并将其托管在服务器上。每当用户访问您的URL时,他将获得本机应用程序而不是网页的外观。 但是如果你不想在服务器上部署它,你可以组合使用senchatouch和phonegap并创建一个可安装的应用程序(例如android的.apk文件) 请参阅本教程,了解如何使用sencha touch生成本机应用程序: http : //android.amolgupta.in/2011/07/hybrid ...
  • 我通过捕捉身体上的touchstart,touchend和touchmove事件以下列方式实现它。 var docBody = document.getElementsByTagName("body")[0]; docBody.addEventListener('touchstart touchend touchmove', function () { alert(' Event has happened'); } 谢谢 I have implemented it the following way ...
  • 您使用的是哪个版本的Sencha SDK和CMD? 最新版本的Cmd不适用于2.1.1之前的SDK版本。 看看这个: Sencha Cmd无法从sencha.cfg找到'app.dir'配置属性 Which version of Sencha SDK & CMD are you using? Latest version of Cmd does not work with SDK versions before 2.1.1. Check this out : Sencha Cmd Unable to loc ...

相关文章

更多

最新问答

更多
  • 如何使用自由职业者帐户登录我的php网站?(How can I login into my php website using freelancer account? [closed])
  • 如何打破按钮上的生命周期循环(How to break do-while loop on button)
  • C#使用EF访问MVC上的部分类的自定义属性(C# access custom attributes of a partial class on MVC with EF)
  • 如何获得facebook app的publish_stream权限?(How to get publish_stream permissions for facebook app?)
  • 如何并排放置两个元件?(How to position two elements side by side?)
  • 在MySQL和/或多列中使用多个表用于Rails应用程序(Using multiple tables in MySQL and/or multiple columns for a Rails application)
  • 如何隐藏谷歌地图上的登录按钮?(How to hide the Sign in button from Google maps?)
  • Mysql左连接旋转90°表(Mysql Left join rotate 90° table)
  • 带有ImageMagick和许多图像的GIF动画(GIF animation with ImageMagick and many images)
  • 电脑高中毕业学习去哪里培训
  • 电脑系统专业就业状况如何啊?
  • IEnumerable linq表达式(IEnumerable linq expressions)
  • 如何在Spring测试中连接依赖关系(How to wire dependencies in Spring tests)
  • Solr可以在没有Lucene的情况下运行吗?(Can Solr run without Lucene?)
  • 如何保证Task在当前线程上同步运行?(How to guarantee that a Task runs synchronously on the current thread?)
  • 在保持每列的类的同时向数据框添加行(Adding row to data frame while maintaining the class of each column)
  • 的?(The ? marks in emacs/haskell and ghc mode)
  • 一个线程可以调用SuspendThread传递自己的线程ID吗?(Can a thread call SuspendThread passing its own thread ID?)
  • 延迟socket.io响应,并“警告 - websocket连接无效”(Delayed socket.io response, and “warn - websocket connection invalid”)
  • 悬停时的图像转换(Image transition on hover)
  • IIS 7.5仅显示homecontroller(IIS 7.5 only shows homecontroller)
  • 没有JavaScript的复选框“关闭”值(Checkbox 'off' value without JavaScript)
  • java分布式框架有哪些
  • Python:填写表单并点击按钮确认[关闭](Python: fill out a form and confirm with a button click [closed])
  • PHP将文件链接到根文件目录(PHP Linking Files to Root File Directory)
  • 我如何删除ListView中的项目?(How I can remove a item in my ListView?)
  • 您是否必须为TFS(云)中的每个BUG创建一个TASK以跟踪时间?(Do you have to create a TASK for every BUG in TFS (Cloud) to track time?)
  • typoscript TMENU ATagParams小写(typoscript TMENU ATagParams lowercase)
  • 武陟会计培训类的学校哪个好点?
  • 从链接中删除文本修饰(Remove text decoration from links)