小编swd*_*don的帖子

org.postgresql.util.PSQLException:错误:列user0_.id不存在 - Hibernate

我有一个使用hibernate映射到postgres数据库的模型类.我的模型类是:

@Entity
@Table(name="USER")
public class User {

    @Id 
    @GeneratedValue
    @Column(name="id")
    private long id;

    @Column(name="username", unique=true)
    private String username;

    @Column(name="email")
    private String email;

    @Column(name="created")
    private Timestamp created;

    public User(long id, String username, String email) {
        this.id = id;
        this.username = username;
        this.email = email;
    }
}
Run Code Online (Sandbox Code Playgroud)

我尝试使用以下查询检索用户名为"adam"的用户:

tx = session.beginTransaction();
TypedQuery<User> query = session.createQuery("FROM User u WHERE u.username = :username", User.class).setParameter("username", "adam");
user = query.getSingleResult();
Run Code Online (Sandbox Code Playgroud)

我得到一个例外,说:

org.postgresql.util.PSQLException: ERROR: column user0_.id does not exist
Run Code Online (Sandbox Code Playgroud)

我的bash shell数据库如下所示:

数据库

hibernate如何将类属性映射到表列?它是基于@Column(name="username")唯一匹配还是根据数据类型和约束(例如唯一/自动增量)尝试匹配?

java postgresql entity hibernate jpa

21
推荐指数
3
解决办法
2万
查看次数

如何在Java中生成长度为n的SecureRandom字符串?

我使用以下方法生成随机字符串:

private String generateSafeToken() {
    SecureRandom random = new SecureRandom();
    byte bytes[] = new byte[512];
    random.nextBytes(bytes);
    return bytes.toString();
}
Run Code Online (Sandbox Code Playgroud)

这给出了一个长度为11的字符串,例如[B@70ffc557.如何使上面的方法返回指定长度的字符串.例如20个字符?

java secure-random

12
推荐指数
1
解决办法
7426
查看次数

完整 .NET Framework 控制台应用程序中的 JSON 配置

我有一个面向 .NET 4.7.1 的控制台应用程序。我正在尝试在我的 .Net Framework 应用程序中使用 .net core 之类的配置。我的`App.config 是:

<configuration>
  <configSections>
    <section name="configBuilders" type="System.Configuration.ConfigurationBuildersSection, System.Configuration, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" restartOnExternalChanges="false" requirePermission="false" />
  </configSections>
  <configBuilders>
    <builders>
    <add name="SimpleJson"
         jsonFile="config.json"
         optional="false"
         jsonMode="Sectional"
         type="Microsoft.Configuration.ConfigurationBuilders.SimpleJsonConfigBuilder, Microsoft.Configuration.ConfigurationBuilders.Json, Version=1.0.0.0, Culture=neutral" /></builders>
  </configBuilders>
Run Code Online (Sandbox Code Playgroud)

我有一个文件config.json,其属性“始终复制”设置为True. config.json好像:

  {
  "appSettings": {
    "setting1": "value1",
    "setting2": "value2",
    "complex": {
      "setting1": "complex:value1",
      "setting2": "complex:value2"
    }
  },

  "connectionStrings": {
    "mySpecialConnectionString": "Dont_check_connection_information_into_source_control"
  }
}
Run Code Online (Sandbox Code Playgroud)

然后,在我的main方法中,我尝试读取一个配置值,如:

var config = ConfigurationManager.AppSettings
Run Code Online (Sandbox Code Playgroud)

但是,的值config始终为空。我尝试了以下方法:

  1. 尝试更改jsonFile~/config.json; …

.net c# configuration json asp-net-config-builders

10
推荐指数
2
解决办法
1万
查看次数

处理彼此依赖的多个git分支

我在Git上维护一个项目的4个分支,结构如下.

  • 学生
  • 老师
  • 认证

问题是我在最后创建了"authentication"分支,并从这个分支添加了一些代码.现在,我切换到"老师"分支继续工作.但是,我需要在"身份验证"模块中添加一些功能来处理"教师"模块.但我还没有完成"身份验证"模块的合并.用git处理这个问题的正确方法是什么?谢谢.

git github git-branch

7
推荐指数
1
解决办法
2343
查看次数

如何在.Net Core中创建分层内存配置

我想按照使用嵌套字典来填充IConfiguration. 我目前的方法是这样的。

我有一本这样的字典:

var inMemConfig = new Dictionary<string, object>();
inMemConfig["section1"] = new Dictionary<string, string>();
inMemConfig["section2"] = new Dictionary<string, object>();
inMemConfig["deepNest"] = new Dictionary<string, object>();
// Excluding a cast below: 
inMemConfig["deepNest"]["list"] = new List<Dictionary<string, string>>();
inMemConfig["deepNest"]["dict"] = new Dictionary<string string>();
Run Code Online (Sandbox Code Playgroud)

填充上面的字典后,我尝试使用ConfigurationBuilder如下所示。

var builder = new ConfigurationBuilder();
var configuration = builder.AddInMemoryCollection(inMemConfig).Build(); 
Run Code Online (Sandbox Code Playgroud)

这显然会给编译器错误,该错误inMemConfig需要为以下类型:IEnumerable<KeyValuePair<string, string>>

是否不可能创建分层内存配置,如果是的话,非常感谢任何正确方向的指针。谢谢。

configuration .net-core-2.1

7
推荐指数
1
解决办法
3028
查看次数

WSO2 身份服务器 - Carbon 无法执行 Java

我使用的是 Ubuntu 16.04 64 位。我安装了 Oracle JDKjdk1.8.0_144/usr/local/java设置了符号链接,如下所示。

$ sudo update-alternatives --install "/usr/bin/java" "java" "/usr/local/java/jdk1.8.0_144/jre/bin/java" 1
$ sudo update-alternatives --install "/usr/bin/javac" "javac" "/usr/local/java/jdk1.8.0_144/bin/javac" 1
$ sudo update-alternatives --install "/usr/bin/javaws" "javaws" "/usr/local/java/jdk1.8.0_144/jre/bin/javaws" 1
$ sudo update-alternatives --set java /usr/local/java/jdk1.8.0_144/jre/bin/java
$ sudo update-alternatives --set javac /usr/local/java/jdk1.8.0_144/bin/javac
$ sudo update-alternatives --set javaws /usr/local/java/jdk1.8.0_144/jre/bin/javaws
Run Code Online (Sandbox Code Playgroud)

之后,我按照WSO2文档中的安装指南进行设置,JAVA_HOME如下所示。

nano /.bashrc
Run Code Online (Sandbox Code Playgroud)

添加了变量:

export JAVA_HOME=/usr/local/java/jdk1.8.0_144
export PATH=${JAVA_HOME}/bin:${PATH}
Run Code Online (Sandbox Code Playgroud)

我关闭旧终端并打开一个新终端并运行:

echo $JAVA_HOME
Run Code Online (Sandbox Code Playgroud)

我得到

/usr/local/java/jdk1.8.0_144
Run Code Online (Sandbox Code Playgroud)

但是,当我运行时sh wso2server.sh,我收到错误:

JAVA_HOME is not defined correctly.
CARBON cannot execute …
Run Code Online (Sandbox Code Playgroud)

java wso2 ubuntu-16.04 wso2-identity-server

6
推荐指数
1
解决办法
7593
查看次数

Asp.Net Core WebApi 的身份验证失败并显示“取消保护票证失败”

当我将 Bearer 令牌与受保护的 AspNetCore 控制器一起使用时[Authorize],我收到日志消息:

info: Microsoft.AspNetCore.Authentication.Cookies.CookieAuthenticationHandler[7]
      Identity.Application was not authenticated. Failure message: Unprotect ticket failed
Run Code Online (Sandbox Code Playgroud)

我试图了解这意味着什么以及可能导致这种情况的原因。

StartupApi的类具有以下设置。Api 使用 AspNet Identity Core。

public void ConfigureServices(IServiceCollection services)
{
    services.AddDbContext<UserAccountDbContext>(options => options.UseSqlServer(connectionString,
                                                                                     sql => sql.MigrationsAssembly(MigrationsAssembly)));

    services.AddIdentity<UserAccount, IdentityRole>()
                    .AddEntityFrameworkStores<UserAccountDbContext>();

    services.AddTransient<UserManager<UserAccount>>();

    services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2);

    services.AddAuthorization();

    services.AddAuthentication("Bearer")
            .AddJwtBearer("Bearer", options =>
                                             {
                                                options.Authority = _configuration.OAuth2.ServerUri;
                                                options.RequireHttpsMetadata = false;
                                                options.Audience = "api";
                                            });
        }
Run Code Online (Sandbox Code Playgroud)

和:

public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
    if (env.IsDevelopment())
    {
        app.UseDeveloperExceptionPage();
    }

    app.UseAuthentication();
    app.UseMvc();
}
Run Code Online (Sandbox Code Playgroud)

对调用者的响应是 Unauthorized (401),没有任何解释。

编辑:

正如评论所建议的那样,我认为这与 cookie …

c# authentication oauth-2.0 asp.net-core-identity asp.net-core-2.2

6
推荐指数
1
解决办法
1万
查看次数

为什么await/async的结果未定义?

我有这样的路线:

router.get("/my_resource", myController.getResult);
Run Code Online (Sandbox Code Playgroud)

然后我的控制器是这样的:

getResult: async (req, res, next) => {
    try {
      const param = req.query.param;
      let response = {};
      if (param) {
        let [result1, result2] = await Promise.all([myModel.getResult1(param), myModel.getResult2(param)]);
        console.log(result1);
        console.log(result2);
      }
      res.send(response);
    } catch (e) { 
        next(e);
    }
  }
Run Code Online (Sandbox Code Playgroud)

我的模型(正在查询 mongodb)看起来像:

getResult1: (param) => {
    new Promise((resolve, reject) => {
      MongoSchema1.findById(param, (error, result) => {
        if (error) return reject(error);
        resolve(result ? result : {});
      }).select("field1 field2");
    })
  }

getResult2: (param) => {
  new Promise((resolve, reject) => { …
Run Code Online (Sandbox Code Playgroud)

javascript express async-await

5
推荐指数
1
解决办法
3755
查看次数

在 Golang 中将 JSON 中的字符串解析为枚举

我有一个枚举定义为

type MyEnum int

const(
   FirstEnum MyEnum = iota
)
Run Code Online (Sandbox Code Playgroud)

然后,我有一个包含键值对的 json "Key": "FirstEnum"。我就是这样解组的。

var data map[string]interface{}
err := json.Unmarshal([]byte(json), &data)
x := data["key"].(MyEnum)
Run Code Online (Sandbox Code Playgroud)

但是,当我运行此命令时,我收到错误:

panic: interface conversion: interface {} is string, not ps.Protocol [recovered]
        panic: interface conversion: interface {} is string, not ps.Protocol
Run Code Online (Sandbox Code Playgroud)

有没有办法让它像 Go 中枚举的字符串表示形式到枚举类型的正常转换一样工作?

enums json go unmarshalling

5
推荐指数
1
解决办法
3万
查看次数

如何在AspNet Core gRPC Service中导入protobuf知名类型

我正在摸索如何将“google/protobuf/empty.proto”导入到我的 proto 文件中。到目前为止我在做什么:

  1. 在我的 .csproj 文件中,我添加了以下内容:

    <Project Sdk="Microsoft.NET.Sdk.Web">
    
       <PropertyGroup>
          <TargetFramework>netcoreapp3.0</TargetFramework>
       </PropertyGroup>
    
       <ItemGroup>
          <Protobuf Include="C:\Users\me\.nuget\packages\google.protobuf.tools\3.10.0\tools\google\protobuf\*.proto" GrpcServices="Server"/>
          <Protobuf Include="Protos\*.proto" GrpcServices="Server" />
       </ItemGroup>
    
       <ItemGroup>
          <PackageReference Include="Grpc.AspNetCore" Version="2.23.2" />
          <PackageReference Include="System.Reactive" Version="4.1.6" />
       </ItemGroup>
    
    </Project>
    
    Run Code Online (Sandbox Code Playgroud)
  2. 在我的项目文件夹中,我有一个名为“Protos”的文件夹,其中有一个 test.proto 文件,我想在其中使用“empty.proto”,例如:

import "google/protobuf/empty.proto";

但是,我收到错误File not found in project。我也不喜欢在ItemGroup. 使用 google protobuf 知名类型的正确方法是什么?

c# protocol-buffers grpc asp.net-core

5
推荐指数
2
解决办法
2321
查看次数